Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Put a custom post type on your WordPress home page.
Plugin Name: CPT On Home Page
Author: Christopher Davis
Author URI:
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