WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] Get posts by (co)author (6 posts)

  1. plopi
    Member
    Posted 1 year ago #

    Hi,
    I'm using the Co Author plus plugin,
    and I can't figure out how to retrieve all the posts by one (co) author knowing the plugin is using taxonomies.
    Any tips? thanks.

    http://wordpress.org/extend/plugins/co-authors-plus/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    WP_Query is your friend. Something like this should work:

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

  3. plopi
    Member
    Posted 1 year ago #

    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.

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

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

  5. plopi
    Member
    Posted 1 year ago #

    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)

  6. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    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'
    		)
    	)
    );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags