Skip Navigation

[Resolved] How to show all posts except logged in authors in a view

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by davidR-12 1 year, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2613083

I have a list of my posts (The logged in user) on a page. Below that I want to add a list of all other posts minus those posts. How do I do this?

#2613389

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To exclude the current author posts from the result you can use the view's filter hook: wpv_filter_query

You can create a view to to display your desired post type and format the loop output as required and then add the following code to the "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

add_filter( 'wpv_filter_query', 'func_remove_currnet_author_posts', 10, 3);
function func_remove_currnet_author_posts( $query_args ,$view_settings, $view_id ) {
    global $current_user; 
   
    if ( in_array($view_id, array( 99999) ) ) {
       
            
      $current_author_posts = new WP_Query( 
                        array(
                            'post_type' => array('student'),
                            'posts_per_page' => -1,
                            'author__not_in'=>array($current_user->ID),
                            'fields'=>"ids"
                             
                ));
       $current_author_found_posts = $current_author_posts ->posts;
         
       $query_args['post__not_in'] = $current_author_found_posts ;
       
    }
     
    return $query_args;
}

Where:
- replace 99999 with your original view ID
- Replace 'student' with your original post type slug

#2613457

Hi Minesh,

Thank you for the quick response. However, that doesn't do anything. The posts of the logged in author are sill displayed in the view.

David

#2613459

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share admin access details and problem URL where you added your view to display non author posts.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2613467

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2613469

Sorry I deleted the post as I gave the wrong details. Can you send another private message request please?

#2613471

Sorry I deleted the post as I gave the wrong details. Can you send another private message request please? I am writing this again as it looks like our wires might have become crossed.

#2613653

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I have set the next reply to private which means only you and I have access to it.

#2614355

Hi Minesh,

The requirements changed and the user wanted a list of authors with their posts so I was able to fix the duplicate issue by using the option to not display the current logged in user in that view.

Thank you for your help on this.

David

#2614363

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Great - you are welcome to close this ticket.

#2614423

My issue is resolved now. Thank you!