pcarlow
Member
Posted 6 years ago #
Hi,
I'd like to capture the value of the optioncount arguments in the wp_list_cats function and put it into a php variable.
Right now I am using:
wp_list_cats('&optioncount=1')
Which displays the category name and the number of entries in that category. I just want the number in a php variable. Thanks!
pcarlow
Member
Posted 6 years ago #
I came up with this silly solution:
<?php $count = wp_list_cats('recurse=1&optioncount=1') ?>
<?php $new_string = ereg_replace("[^0-9]", "", $count);?>
<?php echo $new_string ?>
Only problem is if the category has a number in the name. There's gotta be a better way...
Something like the to count the number of posts in Category 1?
<?php $cat_count = $wpdb->get_var("SELECT category_count from $wpdb->categories WHERE cat_ID = '1'"); ?>
pcarlow
Member
Posted 6 years ago #
Is there any easy way to get the category id? I don't want to have to supply it. It needs to be dynamic. Thanks!
Since you look like you're getting into some coding take a look at:
Function_Reference/wpdb_Class
Database Description
stew278
Member
Posted 6 years ago #
Pearlow ... did you get this issue resolved? If so, can you post?