Adding or Including custom post type to default WordPress loop by altering the ‘pre_get_posts’ function. Here it use add_action() function. This will help to display those posts (custom posts) alongside the default posts in the regular post feed.
Add this in you functions.php
file
|
function add_custom_post_type_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { // if ( is_home() ) { // Use this if its not for main query $query->set( 'post_type', array('post', '2nd-post-type', '3rd-post-type') ); } } add_action( 'pre_get_posts', 'add_custom_post_type_to_query' ); |
Read More