Title: Capture a Function Argument as a PHP Variable
Last modified: August 18, 2016

---

# Capture a Function Argument as a PHP Variable

 *  [pcarlow](https://wordpress.org/support/users/pcarlow/)
 * (@pcarlow)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/)
 * 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](https://wordpress.org/support/users/pcarlow/)
 * (@pcarlow)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/#post-343471)
 * 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…
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/#post-343496)
 * 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](https://wordpress.org/support/users/pcarlow/)
 * (@pcarlow)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/#post-343515)
 * 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!
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/#post-343600)
 * Since you look like you’re getting into some coding take a look at:
 * [Function_Reference/wpdb_Class](http://codex.wordpress.org/Function_Reference/wpdb_Class)
   
   [Database Description](http://codex.wordpress.org/Database_Description)
 *  [stew278](https://wordpress.org/support/users/stew278/)
 * (@stew278)
 * [20 years ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/#post-343909)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [stew278](https://wordpress.org/support/users/stew278/)
 * Last activity: [20 years ago](https://wordpress.org/support/topic/capture-a-function-argument-as-a-php-variable/#post-343909)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
