Hope someone can help me with this. I have a custom post type (‘article’) in my WordPress installation, and I’d like to display those posts alongside the default posts in the regular post feed.

This is my current loop:

<?php
    if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        global $more;
        $more = 0;

    //include the post template
    locate_template( array( 'includes/post-template.php' ), true, false );
}

locate_template( array( 'includes/post-pagination.php' ), true, false );

}else {
_e( 'No posts available', 'pexeto' );
}
?>

2 Answers
2

You need something like this in you functions.php file, I’m using the action Pieter suggested.

function add_custom_post_type_to_query( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', array('post', 'article') );
    }
}
add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

You can read more about the pre_get_posts in the docs.

Leave a Reply

Your email address will not be published. Required fields are marked *