Created
February 19, 2012 15:55
-
-
Save chrisguitarguy/1864416 to your computer and use it in GitHub Desktop.
Put a custom post type on your WordPress home page.
This file contains 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 | |
/* | |
Plugin Name: CPT On Home Page | |
Author: Christopher Davis | |
Author URI: http://christopherdavis.me | |
License: GPL2 | |
*/ | |
/** | |
* Change this to be what you want to include on the home page. | |
* | |
* eg define( 'CDUD_TYPE', 'your_post_type' ); | |
*/ | |
define( 'CDUD_TYPE', 'page' ); | |
add_filter( 'parse_query', 'cd_wprirc1_parse_query' ); | |
/** | |
* Hook into parse query, which gets fired before posts are fetched. | |
* Check to see if we're on the home page AND if this is the main loop | |
* before changing anything. | |
* | |
* $query is passed in by reference (like a pointer in C), so you can | |
* change it in place. No need to "return" it. | |
*/ | |
function cd_wprirc1_parse_query( $query ) | |
{ | |
if( ! $query->is_main_query() ) return; | |
if( is_home() || is_search() || is_tax() || is_category() || is_tag() || is_archive() ) { | |
$query->query_vars['post_type'] = array( 'post', CDUD_TYPE ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment