WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] 2 authors, but only the first can see post (8 posts)

  1. Iamhere
    Member
    Posted 1 year ago #

    Hi

    Remarkable plugin, thank you.

    I have activated the plugin and have assigned 2 authors to one post.
    The first author that is listed logs in and can see the post no worries, but the second author logs in cannot see the post at all.

    I am using some code to restrict the author to only see their own post.
    I've disabled this but still can't see the post with the 2nd author.

    Suggestions please?
    Thanks

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

  2. Iamhere
    Member
    Posted 1 year ago #

    I am using some code to restrict the author to only see their own post.
    I've disabled this but still can't see the post with the 2nd author.
    This is the code I am using to restrict users to their posts.

    I am pretty certain this is the culprit as when I disable this, I can see all posts and edit the co-author post.

    So the question is - how to edit this to work with multiple-authors?

    function posts_for_current_author($query) {
    	global $pagenow;
    
    	if( 'edit.php' != $pagenow || !$query->is_admin )
    	    return $query;
    
    	if( !current_user_can( 'manage_links' ) ) {
    		global $user_ID;
    		$query->set('author', $user_ID );
    	}
    
    	return $query;
    }
    add_filter('pre_get_posts', 'posts_for_current_author');

    In the above code, I also tried with commenting out

    // if( !current_user_can( 'manage_links' ) ) {

    But this still had no effect.

    Only commenting out the entire code above worked.
    I was then able to login as the second Author, see the post and edit it.

    However, I need to use this code to restrict the author to see only their own post (there are many authors and many posts and the authors are newbies so this is attempting to keep things easy for them when they log in) - so how to make it recognise multiple authors?

  3. solaceten
    Member
    Posted 1 year ago #

    This is also something I would like to resolve as I have a similar set up and only the primary author (1st allocated) can see the post - the others see nothing.

    Is there a way to declare global $user_ID; to pick up the co-authors first? I think that would solve it, but need the correct hook to do that.
    I will experiment with this;

    $co_authors = get_coauthors( $post->ID );

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    'author_name' would be a better query param to set than 'author':

    $query->set( 'author_name', wp_get_current_user()->user_login );

  5. Iamhere
    Member
    Posted 1 year ago #

    Hi Daniel

    Thank you for your reply. I tried your code but it does not work.
    The second author still cannot see or edit the post.

    Any further suggestions?

  6. Iamhere
    Member
    Posted 1 year ago #

    I should also mention that I am using custom post type (advanced custom fields) would that need to be taken into consideration?

  7. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    You also need to set $query->is_author = true too:

    function posts_for_current_author($query) {
    	global $pagenow;
    
    	if ( 'edit.php' != $pagenow || !$query->is_admin )
    		return $query;
    
    	if ( ! current_user_can( 'manage_options' ) ) {
    		$query->is_author = true;
    		$query->set( 'author_name', wp_get_current_user()->user_nicename );
    	}
    }
    add_filter('parse_query', 'posts_for_current_author');
  8. genieforge
    Member
    Posted 11 months ago #

    What a nice man, you just saved me hours. This plugin has so much support! Brilliant!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags