[Resolved] Add Pages and Posts to Blog Archive Page

Home Forums Support [Resolved] Add Pages and Posts to Blog Archive Page

Home Forums Support Add Pages and Posts to Blog Archive Page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1312069
    Mushfiqur

    Blog archive pages only include Posts. I am looking to add my Pages in there as well. All of my article are done as pages.

    In my previous theme, I used this code:

    		
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $allarticles = new WP_Query( array( 'post_type' => array('post','page'), 
    				    'posts_per_page'=> 10, 
    				    'paged' => $paged));
    		
    global $wp_query;
    $wp_query = $allarticles;
    while ($wp_query->have_posts()) : $wp_query->the_post();
       get_template_part('content', 'loop');
    endwhile;
    

    How would I achieve this in GeneratePress? Thanks!

    #1312895
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You could try this:

    add_action( 'pre_get_posts', function( $query ) {
        if ( is_admin() || ! $query->is_main_query() ) {
            return;
        }
    
        if ( $query->is_archive() || $query->is_home() ) {
            $query->set( 'post_type', array( 'post', 'page' ) );
        }
    } );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.