I have a Resources page on my client's site that currently lists out the titles of Posts from the blog, sorted alphabetically. This is a simple View that pulls those in. My client is now asking that I add in 4 Pages into the list as well. I thought I could just edit the View, check the box to include Pages in the mix, but now I'm not sure how I can create the query to say something like "show all Posts, and also Pages that have one of these ids". Not sure how to make a query that is WHERE ((item is Post) OR (item is Page and Page ID in {12, 53, 77, 83})). Is something like that possible, either in a single View, or as 2 different Views that are then combined into a single list in a third View? Any help you can provide would be appreciated.
Hello,
It needs custom codes, for example, you can try with Views filter hook wpv_filter_query, add below PHP codes into your theme file "functions.php":
add_filter('wpv_filter_query', function($query, $settings, $view_id){
if($view_id == 123){
add_filter('posts_where', 'add_pages', 10, 2);
}
return $query;
}, 10, 3);
function add_pages($where, $query){
global $wpdb;
$where .= " OR $wpdb->posts.ID IN (456, 789)";
remove_filter('posts_where', 'add_pages', 10);
return $where;
}
Please replace 123 with your post view's ID, replace 456, 789 with those specific page's IDs.
More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/hooks/posts_where/
Thank you for your help. This did exactly what I wanted. Thanks also for the links to the docs. I wasn't aware of that stuff so now I can go dig in on my own to get the full power of Toolset.