Useful Snippets

Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

September 2020
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
282930  

Categories


Types & Views: Excluding posts/pages from a view.

Stanislav KhromovStanislav Khromov

This is also a good snippet for manipulating WP_Query args in general. For stuff Views doesn’t provide a GUI for yet.

Instructions

Add code in your theme/functions.php (Although creating a Plugin would be better, so we don’t have issues if themes are changed later on)

add_filter('wpv_filter_query', 'exclude_specific_page_func', 10, 2);

function exclude_specific_page_func($query, $settings)
{
  if($settings['view_id'] == 123)
  {
    $query['post__not_in'][] = 456;
    $query['post__not_in'][] = 457;
    $query['post__not_in'][] = 458;
  }
  return $query;
}

Source

Views: Post parent is -not- specific page

More info

Screenshot

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
LinkedIn
Twitter
WordPress.org Profile
Visit my other blog

Comments 0
There are currently no comments.