To show the post in a page of my theme

I have to show all the posts from custom type post on my product page. So I am using the Custom Post Type plugin. Now I want to display all the posts in the product page like it was a blog page of WordPress. I am using the code below to display the posts in the product page..

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

    if ( is_page('product') && $query->is_main_query() )
        $query->set( 'post_type', array('products' ) );

    return $query;
}

But I can’t get the page. If there is some other way to display all the posts in the page, then please help me out.

Related posts

Leave a Reply

2 comments

  1. Add this code where you want all post’s change the ID of category and number of post’s…

    <?php
    global $post;
    $args = array( 'numberposts' => 5, 'category' => 3 );
    
    
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :
    setup_postdata($post); ?>
    
    <?php the_title(); ?>
    <?php the_content(); ?>
    
    <?php endforeach; ?>