Hello Everyone, It has been a while.
I am having a go at setting up a basic client area, I have two main CPT: project and client.
I have two relationships: user_client and client_projects.
These work fine in other filtering envioroments(I have beaver builder fl_builder_loop_query_args and this filters it perfectly for the post module), but for the Singular posts/projects it is not playing nice.
I does the default behaviour when no post can be found (error404), but when it is the correct item it just returns standard post archive and the message "Sorry, we couldn't find any posts. Please try a different search." that I think are standard beaver builder templete behavour when empy post is returned.
Cant figure it out, it is definity the relationship args that are effecting it, but can pin point what.
function main_project_query( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if (is_user_logged_in() && current_user_can('administrator') ) {
return;
} else {
$user_id = get_current_user_id();
$client = MB_Relationships_API::get_connected( [
'id' => 'user_client',
'from' => $user_id
] );
if (count($client) > 0) {
$client = $client[0];
$client_id = $client->ID;
} else {
$client_id = null;
}
$query->set( 'relationship', [
'id' => 'client_projects',
'from' => $client_id
]);
}
}
}
add_action( 'parse_query', 'main_project_query' );
Thanks
David