Support » Plugins and Hacks » Co-Authors Plus » [Resolved] Co-Authors Plus and wp_query

[Resolved] Co-Authors Plus and wp_query

  • In this thread, including the co-author as a custom taxonomy in wp_query worked: http://wordpress.org/support/topic/plugin-co-authors-plus-wp_query-not-working-as-it-should?replies=9

    Probably as a result of a later update, that solution no longer works, but it also isn’t needed, because the original problem (where a wp_query by author or author_name listed only the posts on which the person in question was the PRIMARY author) has been solved. Hooraaaay! ‘author_name’ => $user_login totally works in wp_query!

    Here’s the weird thing:

    Individually, my author_name parameter works.
    My tax_query parameter works.
    My meta_query parameter works.

    In combination, my tax_query and my meta_query parameters work when both specified;
    my meta_query and author_name parameters work when both specified.

    But when an author_name AND a tax_query are both specified, I get an empty set, even when there should be posts!

    It has just occurred to me how profoundly unlikely it is for anyone else to have run across this issue, solved it, and currently be reading the support forum…but it can’t hurt to ask.

    However, barring the impossible fantasy of somebody having that very specific answer, it would also be helpful to know if querying the author as a taxonomy should still work, because that’d give me another combination to try.


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


    I’ve put together a document which hopefully explains this better. Let me know what you think of it, and whether you have any follow up questions I should answer with it.

    That has solved it just beautifully. Thank you so much for your help with this, Daniel!

    Plugin Author Daniel Bachhuber



    It’s been a while, but since this is relevant to the same conversation, I’d like to add a follow-up question: Is it possible, using this (or another) method, to display posts from a group of co-authors? Traditionally we might once have used something along the lines of author=1,2,3 but author_name doesn’t accept multiple values, as far as I can figure. Does that mean that since we are without the option of passing author ID values to WP_Query, there’s no way to specify multiple co-authors?

    I though I was making some headway with these arguments, but I think they’re actually just returning everything.

    $query_args = array(
    	'orderby' => 'date',
    		'relation' => 'OR',
    		'author_name' => array('first-author','second-author')

    (Posted this before I realized the problem, haha.)

    Plugin Author Daniel Bachhuber


    You’ll get the most mileage out of using a taxonomy query. Each author is a taxonomy term, and you can include multiple terms in your query.

    I’m probably setting the cause back a bit by not being able to get the tax_query right (I’ve been trying it for a while), but I’ve definitely got something wrong here, as I can’t even get it to return results for a single co-author:

    'tax_query' => array(
    		'taxonomy' => 'author',
    		'field' => 'slug',
    		'terms' => 'first-author'

    This was where I began yesterday, but after referencing the previously-mentioned documentation (http://vip.wordpress.com/documentation/list-posts-by-a-co-author/), thought I was mistaken and needed to go back to author_name. There’s nothing like trying to piece together progress made eight months prior, huh?

    Plugin Author Daniel Bachhuber


    The term slug can be prefixed with cap-. If you have access to the database, check to make sure that your author term doesn’t have that prefix.

    Yes! Prefixing cap- to each of my co-authors’ slugs has done the trick, and I’m able to successfully include posts from a group of authors by using an array of cap- slugs. Thank you very much (as always), Daniel.

    I have a similar problem. If I call wp_query with a single author id, works only if is the first co-author. If the co-author is second wp_query is empty. If in post edit, i switch the co-authors, that last author id works.

    Plugin Author Daniel Bachhuber


    @cristian Can you provide an example of the code you’re using?

    $args = array ('post_type' => 'materii', 'posts_per_page' => -1, 'order' => 'ASC');
    foreach($_POST as $key => $value) if($value!=NULL) $args[$key] = $value;
    $wp_query = new WP_Query( $args );

    and the $_POST[‘author’]={id}

    Plugin Author Daniel Bachhuber


    Ok. Similar to above, you’ll want to write a taxonomy query because the second co-author is actually a term relation, not stored in post_author column.

    Understood. I’ll try it. Thanks.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Co-Authors Plus and wp_query’ is closed to new replies.
Skip to toolbar