Site logo

Archived topic

Add Pages and Posts to Blog Archive Page

1 reply · Started by Mushfiqur on June 3, 2020

Viewing posts 1–2 of 2

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!

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' ) );
    }
} );
This archived topic is closed to new replies.