Forums

Co-Authors Plus
[resolved] WP_Query() not working as it should (2 posts)

  1. mkubilayk
    Member
    Posted 4 months ago #

    I am using Co-Authors Plus 2.6.1 and I am trying to show the latest post of each author in the sidebar. Here is the code I am using: ($aUsersID is the sorted user-id list)

    foreach ( $aUsersID as $iUserID ) {
    	$auth = 'author=' . $iUserID;
    	...
    	$author_posts = new WP_Query($auth);
    	...
    	...
    }

    This works great for single-author posts however it does not show the post of a co-author unless s/he is the original author. I can get around this by searching all posts for each author and check whether s/he is in the coauthors list or not and break the while if the case is satisfied. This looks like a definite solution but it is not quite efficient. How can I find a way out besides this one?

    Thanks in advance...

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

  2. Daniel Bachhuber
    Member
    Posted 3 months ago #

    You're correct in that doing a normal WP_Query will only produce the posts where the author is set as the primary author. When your co-authors data is saved, the first author on the list is saved as the primary author, and all authors are saved as terms for the post under the 'author' taxonomy.

    So, the simplest thing to do is to search for all posts with the author set as a taxonomy term. This works much like a normal 'tag' or 'category' query would.

    Let me know if you have any questions as to what the code might look like.

Reply

You must log in to post.

About this Plugin

About this Topic