Skip Navigation

[Resolved] wpv_filter_query with nested views

This support ticket is created 4 years 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.

This topic contains 2 replies, has 1 voice.

Last updated by BrandenT2154 4 years ago.

Author
Posts
#1871047

I have a post type called Manufacturers and another called Reps
both are related many-to-many with an intermediary post type.

in one of my views I have a "manufacturer's index" which is a simple list of Manufacturers, and under each manufacturer is it's related reps. here's the view on the front end: hidden link

I accomplish this by first making a view that lists the manufacturers. then, inside the loop of that view, i have another view that lists all reps associated with the manufacturer in the current loop.

here's the loop:
<div style="font-size: 1.4em;">[wpv-post-title]</div>
<div>[wpv-view name="related-reps"]</div>

This works fine. However, I want to hide manufacturer's that do not have any published reps associated with them.

I think I can do this with php and toolset_get_related_posts if I can filter the query results

to filter the query results, I thought I would be able to use wpv_filter_query

however, when I use this simple wpv_filter_query, it stopes the nested view from working, and i only end up with a list of manufacturers:

function filter_manufacturers_lacking_reps($query_args,$view_settings,$view_id){
if ($view_id == 443){ //only apply to the manufacturer's index view

return $query_args;

}
}

add_filter( 'wpv_filter_query', 'filter_manufacturers_lacking_reps', 99, 3 );

is there a reason that this filter stops nested views? is there something I can do to prevent it? or can i filter the query results in another way?

#1871707

silly me. i think it's the wrong ID

this works

if ($view_id == 443){ //only apply to the manufacturer's index view

}

return $query_args;
}

#1871709

My issue is resolved now. Thank you!