0

I've done a bit of wp_query work before, but always targeting certain categories.

I want to do a wp_query that uses all the categories, but it is not displaying anything.

This is my code:

// WP_Query arguments
$args = array(
    'nopaging' => false,
    'post_type' => 'posts',
    'posts_per_page' => '4',            
    'meta_key' => 'partner',
    'meta_value' => $post_id
);

Nothing is coming through yet and if I add a cat and no:

// WP_Query arguments
$args = array(
    'nopaging' => false,
    'post_type' => 'posts',
    'posts_per_page' => '4',  
    'cat' => '5',
    'meta_key' => 'partner',
    'meta_value' => $post_id
);

It pulls the posts in.

I've searched in Google, but found nothing hence I am asking.

0

It's hard to say exactly why adding the category changes anything, but... The query looks OK... Almost... There are some things that concerns me:

  1. 'post_type' => 'posts', - there is no built-in post type called posts. You should use post in there, unless it's your CPT (but then... I don't think it's a good name ;))

This is the biggest concern. But there are some minor ones also:

  1. 'posts_per_page' => '4', - it should be a number, it will be converted, but why should it have to...
  2. 'nopaging' => false, - it's default value for this arg, so there is no point of setting it.
  • Hey Krzysiek, thanks for pointing out that posts should have been post. That has solved it. I've also remove the no paging too. Cheers :) – bob May 31 '18 at 5:52
  • 1
    Also the post per page need to be set to 4 as I have styled it up like that in CSS :) have a good day mate! – bob May 31 '18 at 5:53

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.