Title: Displaying posts with get_posts &#8211; dynamic category parameter problem
Last modified: October 19, 2016

---

# Displaying posts with get_posts – dynamic category parameter problem

 *  [san_merah](https://wordpress.org/support/users/san_merah/)
 * (@san_merah)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/displaying-posts-with-get_posts-dynamic-category-parameter-problem/)
 * Hi Guys,
 * I’m showing a grid of posts with get_posts() function and trying to control category
   parameter value from a custom field.
 * my code only works if category parameter gets value from echo function when I
   do echo value as a number rather than variable for example:
 *     ```
       $args = array( 
       	'numberposts' => 6,
       	'category'         => '<?php echo "25";?>'
               ,);
       ```
   
 * but it doesn’t when I do something like
 *     ```
       $catid = get_field( "id_of_product_category" );
       $args = array( 
       	'numberposts' => 6,
       	'category'         => '<?php echo $catid;?>'
               ,);
       ```
   
 * at the same time I’am able to
 * `echo $catid;`
 * on the page and it does show correct value set in custom field.
 * Why I can’t get it to work to change category parameter then?
    -  This topic was modified 9 years, 7 months ago by [san_merah](https://wordpress.org/support/users/san_merah/).
    -  This topic was modified 9 years, 7 months ago by [san_merah](https://wordpress.org/support/users/san_merah/).
    -  This topic was modified 9 years, 7 months ago by [san_merah](https://wordpress.org/support/users/san_merah/).

The topic ‘Displaying posts with get_posts – dynamic category parameter problem’
is closed to new replies.

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)

 * 0 replies
 * 1 participant
 * Last reply from: [san_merah](https://wordpress.org/support/users/san_merah/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/displaying-posts-with-get_posts-dynamic-category-parameter-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
