Skip to content

Instantly share code, notes, and snippets.

@danmaby
Last active February 19, 2018 11:56
Show Gist options
  • Save danmaby/2c19b194559dfc8f23427f6c8caeb3bd to your computer and use it in GitHub Desktop.
Save danmaby/2c19b194559dfc8f23427f6c8caeb3bd to your computer and use it in GitHub Desktop.
Add custom post types to WordPress loop
<?php
/**
* Add 'Events' CTP to WP Loop
**/
function add_custom_post_type_to_query( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array('post', 'events') );
}
}
add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment