Skip Navigation

[Resolved] Display CPT bassed on relationship in backend

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Our next available supporter will start replying to tickets in about 2.34 hours from now. Thank you for your understanding.

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 3 replies, has 2 voices.

Last updated by jesusM-6 2 years, 11 months ago.

Assisted by: Minesh.

soporte toolset 07.jpg

Hello, I have the following toolset structure:

-Users "amigo" can create a lof of posts "recomendado"
-User "comercial" can create a post "comercial"
- Relationship one to many between CPT comercial - CPT recomendado

When I am logged in as "comercial" I can see all CPT "recomendado" . But I want to display only the CPT "recomendado" related with me (the logged in user).



Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - on the admin post listing screen of post type "recomendado" on backend (admin), you would like to display only posts that is connected to "comercial" post type that is created by current loggedin user. If this is correct: there is no such feature to filter related posts in backend.

But a workaround could be to use pre_get_posts filter to filter the posts but that needs some custom programming. If you can setup few connected posts and share admin access details as well as "comercial" user access details and share what posts you expect to see when loggedin as comercial user I would be happy to check if I can share any workaround.

*** 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.



Languages: English (English )

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

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

function filter_parent_post_by_author_and_display_related_post_only($query) {
    global $pagenow, $typenow, $current_user;
    if (  is_admin() and 'recomendado' === $typenow && 'edit.php' === $pagenow and in_array('comercial',$current_user->roles) ) {
     global $wpdb;
      $where = get_posts_by_author_sql('comercial',true,$current_user->ID);
      $res = $wpdb->get_col( "SELECT FROM {$wpdb->posts} p $where");
      $related_post_ids = array(0);
      if(!empty($res)) {
      $related_post_ids = toolset_get_related_posts(
add_action( 'pre_get_posts', 'filter_parent_post_by_author_and_display_related_post_only');

When I logged in as "comercial" user you shared, I can see the expected posts now, Can you please confirm it works at your end as well.
- hidden link

More info:


It's great! This is just what I need. Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.