Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Maximilian Euler

Show only “mine” posts in filter

great plugin so far!!
I am just struggling with one little problem. I use that filter to only show “mine” posts of that custom post type:

add_filter( 'views_edit-einsendung', function( $views )
    if( current_user_can( 'manage_options' ) )
        return $views;

    $remove_views = [ 'all','publish','future','sticky','draft','pending','trash' ];

foreach( (array) $remove_views as $view )
    if( isset( $views[$view] ) )
        unset( $views[$view] );
return $views;
} );

But as soon as I set some filter, I can see all posts again. Any ideas how to make users really see only their own posts?


2 years, 10 months ago
Stefan van den Dungen Gronovius

Hi There,

I believe that the hook you’re using does not really filter the posts to the user only. The hook only changes the links that are available on top of the table. Still, when you go to the actual overview page through the menu on the let the user should still see all posts.

When you click on the ‘Mine’ link on top of the table, and use our filtering logic, you should see the filtered post with the user filter still active. Maybe you have another hook in your theme that is filtering the post based on the user. Or at least a hook to filter the query for users only is the way to go to get what you want. Our plugin does not have a way to filter posts based on active user.

You could something like this to ensure that users only see their own posts.

add_filter( 'pre_get_posts', function( WP_Query  $query ){
	if( ! is_admin() || ! $query->is_main_query() || current_user_can( 'manage_options' ) ){

	$query->set( 'author', get_current_user_id() );
2 years, 9 months ago

You must be logged in to reply to this topic.