• 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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter pcarlow

    (@pcarlow)

    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'"); ?>

    Thread Starter pcarlow

    (@pcarlow)

    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

    Pearlow … did you get this issue resolved? If so, can you post?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Capture a Function Argument as a PHP Variable’ is closed to new replies.