Useful Snippets

Welcome!


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

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at Unwanted.cloud

RSS Latest posts from my personal blog


Most viewed posts


Subscribe to RSS feed


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.