-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).
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.
I've added the following code to "Custom Code" section offered by Toolset:
=> enlace oculto
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 p.id FROM {$wpdb->posts} p $where");
$related_post_ids = array(0);
if(!empty($res)) {
$related_post_ids = toolset_get_related_posts(
$res[0],
'comercial-expediente',
'parent',
100,
0,
array(),
'post_id',
'child'
);
}
$query->set("post__in",$related_post_ids);
}
}
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.
- enlace oculto