Home > Software design >  On WordPress Archives Display All Posts
On WordPress Archives Display All Posts

Time:11-17

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 );
}}

CodePudding user response:

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' );
    }
}
  • Related