WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Get posts by (co)author

[Resolved] Get posts by (co)author

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Daniel Bachhuber

    @danielbachhuber

    WP_Query is your friend. Something like this should work:

    $author_posts = new WP_Query( array( 'author' => $author_login ) );

    I tried that,
    it does not work : my query is to retrieve my author posts in a certain category, it retreives me all the posts of that category, ignoring the author.

    Plugin Author Daniel Bachhuber

    @danielbachhuber

    In that case, you’ll want to use a tax query to query multiple taxonomies.

    Ok,
    could you be more specific?
    As i see in the WP_Query example :

    $args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'people',
    			'field' => 'slug',
    			'terms' => 'bob'
    		)
    	)
    );

    In the case of the co authors, what taxonomy am I supposed to use?
    Same question for the ‘field’ parameter.
    I suppose i have to put my user_login for the ‘terms’ parameter.

    To have a more specific example :
    I have to retrive all the posts, in the category ‘news’ from my author ‘john-smith’ (who is a secondary author thanks to the co author plugin, not the primary one)

    Plugin Author Daniel Bachhuber

    @danielbachhuber

    Something like this should work:

    $args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => 'news'
    		),
    		array(
    			'taxonomy' => 'author',
    			'field' => 'slug',
    			'terms' => 'john-smith'
    		)
    	)
    );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Get posts by (co)author’ is closed to new replies.