Skip to content

Instantly share code, notes, and snippets.

@mor10
Created July 14, 2016 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mor10/6c6a2b2393347615b4e9a8f6f259e754 to your computer and use it in GitHub Desktop.
Save mor10/6c6a2b2393347615b4e9a8f6f259e754 to your computer and use it in GitHub Desktop.
Add custom post type to index and search results
<?php
/**
* Include Lecture post type in the main and search queries
*/
function wpcampuscpt_query_filter( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_search() || $query->is_home() ) {
$query->set('post_type', array( 'post', 'lecture' ) );
}
}
}
add_action( 'pre_get_posts', 'wpcampuscpt_query_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment