Both blog post and WooCommerce products on one page

141 views Asked by At

I'm in the process of developing my own theme, but I have run into some problems. I'm trying to display both blog posts and WooCommerce products on the same page - not only on the same page, but in my Bootstrap and Masonry grid.

You can see the page here, where it only shows the WooCommerce products: link

You can see there code here: link

Does any of you know a way to do this?

1

There are 1 answers

1
helgatheviking On

You can use the pre_get_posts filter to modify the query and return multiple post types in the loop.

function so_30900238_query_mod( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;

    if ( is_post_type_archive( 'product' ) ) {
        // Display 50 posts for a custom post type called 'movie'
        $query->set( 'post_type', array( 'product', 'post' ) );
        return;
    }
}
add_action( 'pre_get_posts', 'so_30900238_query_mod'  );

Untested.