WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] Co-Authors Plus and wp_query (15 posts)

  1. notkristina
    Member
    Posted 1 year ago #

    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.

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

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    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.

  3. notkristina
    Member
    Posted 1 year ago #

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

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    :)

  5. notkristina
    Member
    Posted 6 months ago #

    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?

  6. notkristina
    Member
    Posted 6 months ago #

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

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

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

  7. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 6 months ago #

    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.

  8. notkristina
    Member
    Posted 6 months ago #

    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(
    	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?

  9. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 6 months ago #

    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.

  10. notkristina
    Member
    Posted 6 months ago #

    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.

  11. Cristian Sarov
    Member
    Posted 5 months ago #

    Hi!
    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.

  12. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 5 months ago #

    @Cristian Can you provide an example of the code you're using?

  13. Cristian Sarov
    Member
    Posted 5 months ago #

    $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}

  14. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 5 months ago #

    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.

  15. Cristian Sarov
    Member
    Posted 5 months ago #

    Understood. I'll try it. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic