Support » Fixing WordPress » wp_query filtering by category and author

  • Resolved TwoThirdsWater

    (@twothirdswater)


    I would like to use wp_query to get all posts within a particular category that are by a particular author.

    This would seem to me to be pretty simple, and have created the following code

    $args = array(
    		  'post_type' => 'post',
    		  'posts_per_page' => $numStories,
    		  'cat' => get_post_meta(getSettingsPageID(), "blog_category_id", true),
    		  'byAuthor' => $byAuthor
    		  );
    
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query($args);

    but instead of getting me all posts where both cat AND author match, I get all posts where cat OR author match.

    How do I get BOTH conditions to be matched please?

Viewing 1 replies (of 1 total)
  • Idiot Idiot Idiot.

    No sooner do I post it do I see that the filter needs to be ‘author’ not byAuthor. Couldn’t see the wood for the trees.

    For anyone who stumbles across this post, the working code is:

    $args = array(
    		  'post_type' => 'post',
    		  'posts_per_page' => $numStories,
    		  'cat' => $catID,
    		  'author' => $authorID
    		  );
    
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query($args);

Viewing 1 replies (of 1 total)
  • The topic ‘wp_query filtering by category and author’ is closed to new replies.