Keyword

k2 items within category count only include published items

More
8 years 2 months ago #155990 by jim
Hi, I currently have the following code which displays perfectly the number of k2 items/articles within a category.

<?php
$cat_id = $this->item->category->id;
$db = JFactory::getDBO();
$select = "SELECT COUNT(*) FROM #__k2_items WHERE catid = $cat_id";
$db->setQuery($select);
$noitems = $db->loadresult();
echo $noitems;
?>

But the only problem is this includes unpublished items, therefore I need to modify this to only count 'Published' k2 items/articles.

Any help would be very much appreciated! Many thanks in advance!

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 months ago #156004 by Krikor Boghossian
Replied by Krikor Boghossian on topic k2 items within category count only include published items
In the query you need to add this parameter -> AND published=1
$select = "SELECT COUNT(*) FROM #__k2_items WHERE catid = $cat_id AND published=1";

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum