Created
July 14, 2016 18:53
-
-
Save mor10/6c6a2b2393347615b4e9a8f6f259e754 to your computer and use it in GitHub Desktop.
Add custom post type to index and search results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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