I'm going a bit crazy on this one. I'm trying to display a list of posts in a category on an Admin page in a plugin I am writing. The following code works fine on my dev server (OS X/Apache):

$args = array(
    'posts_per_page' => $pageSize,
    'offset'=> $offset,
    'category' => 9

$posts = get_posts($args);

foreach ($posts as $key => $aPost) {

As you might suspect, I get only posts in the category with an ID of 9. Now, on my production server (Linux/Nginx) it shows all posts - as if the category argument was never set. I only mention the nginx/apache/linux/os x as everything else is running the same - same themes and plugins installed (with the exception of Jetpack on the production server).

Any thoughts?

  • have you tried deactivating the Jetpack plugin? Mar 2 '14 at 7:43
  • 1
    You said you have the same themes and plugins, but what about PHP version/ activated PHP modules (long shot there)? Did you import the dev database so that all ID's are the same in production?
    – Ian
    Mar 2 '14 at 9:02
  • PHP on production is 5.4.6 while on the dev server is 5.3.26 - do you really thing the php version could do it? Given that they are both fairly up to date? As far as the ID#s, it isn't responding to any id version. So on production, it just ignores 'category' as if it wasn't there, regardless of the value. Mar 2 '14 at 14:01
  • @PieterGoosen Yep - tried jetpack deactivation didn't help. Mar 2 '14 at 14:23

Ok. After a frustrating weekend I have a workaround (but still not real reason why the simpler version worked on one install and not another!)

$args = array(
    'posts_per_page' => $pageSize,
    'offset'=> $offset,
    'tax_query' => array(
            'taxonomy' => 'category', 
            'field' => 'term_id', 
            'terms' => 9

While this is a totally workable solution, I'm still baffled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.