Advertisement
marjwyatt

pre_get_posts for cpt

Jan 24th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. <?php
  2. // Include custom post type in default category archives
  3. // Ref link: http://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page
  4. add_filter('pre_get_posts', 'query_post_type');
  5. function query_post_type($query) {
  6.   if( is_category() || is_tag() || is_home() && empty( $query->query_vars['suppress_filters'] ) ) {
  7.     $post_type = get_query_var('post_type');
  8.     $post_type = array('post','adverts','nav_menu_item'); // replace cpt to your custom post type
  9.     $query->set('post_type',$post_type);
  10.     return $query;
  11.     }
  12. }
  13. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement