Thomas Burrows
Thomas Burrows

Reputation: 37

On WordPress Archives Display All Posts

I need to be able to display all posts on WordPress archive pages, but I do not know how to make that happen. I have tried using the following code, but it does not work.

add_action('pre_get_posts', 'all_posts');
function all_posts( $query ) {
if ($query->is_category()){
$query->set( 'posts_per_page' => -1, true );
}}

I tried changing it into this:


add_action('pre_get_posts', 'all_posts');
function all_posts( $query ) {
if ($query->is_category()){
$query->set( '-1' , true );
}}

Upvotes: 1

Views: 31

Answers (1)

Coopero
Coopero

Reputation: 296

Try this

add_action('pre_get_posts', 'all_posts');
function all_posts( $query ) {
    if ($query->is_category()){
        $query->set( 'posts_per_page' , -1 );
        $query->set( 'post_type', 'post' );
    }
}

Upvotes: 1

Related Questions