Skip to content

Instantly share code, notes, and snippets.

@bigdigital
Last active February 6, 2017 08:32
Show Gist options
  • Save bigdigital/2ac1db3a0662ff7e2b72c0c12390505d to your computer and use it in GitHub Desktop.
Save bigdigital/2ac1db3a0662ff7e2b72c0c12390505d to your computer and use it in GitHub Desktop.
Add custom post type search in wordpress
<?php
add_filter( 'pre_get_posts', 'custom_post_search' );
function custom_post_search( $query ) {
$post_type = get_query_var('post_type');
if ( $query->is_search && !is_admin() ) {
$query->set( 'post_type', array( 'post', 'movies', 'products', 'portfolio', 'ai1ec_event' ) );
}
else if ( $query->is_search && is_admin() && $post_type == 'ai1ec_event' ){
$query->set( 'post_type', array( 'ai1ec_event' ) );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment