[Resolved] Views -Select posts in a relationship that are related to any of multiple values
This support ticket is created 3 years, 5 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
For example, suppose that your View ID is 12345 and the target status posts IDs are 4, 6 & 8 and the involved relationship slug is "membership-status-person", then the function will look like this:
add_filter( 'wpv_filter_query', 'filter_specific_status_fn', 1000 , 3 );
function filter_specific_status_fn( $query_args, $view_settings ) {
if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
// IDs of the required statuses
$req_statuses = array(4, 6, 8);
foreach ( $req_statuses as $post_array ) {
// get parent post in a relationship
$query_by_element = $post_array; // ID of post to get relationship from
$relationship = 'membership-status-person'; // relationship slug
$query_by_role_name = 'parent'; // $query_by_element is a parent in this relation
$limit = 999999; // defaults
$offset = 0; // defaults
$args = array(); //nothing needed
$return = 'post_id'; // We want Post ID
$role_name_to_return = 'child'; // We want child.
$get_results = toolset_get_related_posts(
$query_by_element,
$relationship,
$query_by_role_name,
$limit,
$offset,
$args,
$return,
$role_name_to_return
);
foreach ($get_results as $get_result ) {
$query_args['post__in'][] = $get_result;
}
}
}
return $query_args;
}
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/