Skip to content

Instantly share code, notes, and snippets.

@onestepcreative
Last active December 15, 2015 13:28
Show Gist options
  • Select an option

  • Save onestepcreative/5267153 to your computer and use it in GitHub Desktop.

Select an option

Save onestepcreative/5267153 to your computer and use it in GitHub Desktop.
Add more robust functionality for custom post types in Wordpress. Adds custom post type "video" to search results & archive pages.
<?php
// =========================================================================
// ====== MORE ROBUST CUSTOM POST TYPE INTEGRATIONS
// =========================================================================
function combatPostTypeArchives($query) {
if(is_category() || is_tag() && empty( $query->query_vars['suppress_filters'])) {
// SET POST_TYPES TO INCLUDE VIDEOS
$query->set('post_type', array('post', 'videos'));
return $query;
}
}
function combatPostTypeSearch($query) {
if ($query->is_search) {
// SET POST_TYPES TO INCLUDE VIDEOS
$query->set( 'post_type', array( 'post', 'page', 'feed', 'videos'));
}
return $query;
}
// HOOK CUSTOM POST TYPES INTO ARCHIVE PAGES
add_filter( 'pre_get_posts', 'combatPostTypeArchives' );
// HOOK CUSTOM POST TYPES INTO SEARCH RESULTS
add_filter( 'the_search_query', 'combatPostTypeSearch' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment