Last active
December 15, 2015 13:28
-
-
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.
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 | |
| // ========================================================================= | |
| // ====== 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