Skip Navigation

[Resolved] WordPress Custom archive output numbers of posts?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 4.98 hours from now. Thank you for your understanding.

This topic contains 7 replies, has 2 voices.

Last updated by thomasS-11 6 years, 9 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#286197

I am trying to: Display all posts in WordPress Custom Archive (i created a Archive for my custom category)

Instead, I got: 10 posts per page and a pagination at the bottom of the page...

#286272

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

You can setup the numbers of posts in wordpress archive page like this:
Goto your WP admin side, Settings-> Reading
In option "Blog pages show at most", set it to a large number.

#286297

This is not possible per post type?

#286778

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

You can try WordPress action hook pre_get_posts, for example:

function hwl_home_pagesize( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;

    if ( is_post_type_archive( 'CPT1' )  || is_post_type_archive( 'CPT2' )) {
        // Display 50 posts for a custom post type called 'movie'
        $query->set( 'posts_per_page', 50 );
        return;
    }
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );

Please replace CPT1 and CPT2 with your custom post type slugs.

More help:
pre_get_posts
This hook is called after the query variable object is created, but before the actual query is run.

Changing the number of posts per page, by post type
http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Changing_the_number_of_posts_per_page.2C_by_post_type

#287186

I cant get this to work with Types..
I have a taxonomy called DJ kategorier with the slug "djs".

i have tried both

function hwl_home_pagesize( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;
 
    if ( is_post_type_archive( 'djs' )  || is_post_type_archive( 'dj-kategorier' )) {
        // Display 50 posts for a custom post type called 'movie'
        $query->set( 'posts_per_page', 50 );
        return;
    }
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );

and

function hwl_home_pagesize( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;
 
    if ( is_post_type_archive( 'djs' ) ) {
        // Display 50 posts for a custom post type called 'movie'
        $query->set( 'posts_per_page', 50 );
        return;
    }
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );

but none of them seems to work...

#287201

And can you please ask the Dev team if you can implement such a feature in the future? it would be very handy.

Thanks

#287214

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

1) for the taxonomy called DJ kategorier with the slug "djs"
You will need use wordpress function is_tax()
For example:

function hwl_home_pagesize( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;
  
    if ( is_tax( 'djs' ) ) {
        $query->set( 'posts_per_page', 50 );
        return;
    }
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );

More help:
is_tax
This Conditional Tag checks if a custom taxonomy archive page is being displayed. This is a boolean function, meaning it returns either TRUE or FALSE
http://codex.wordpress.org/Function_Reference/is_tax

2) I put it into our to-do list as a feature request, our developers will take care of it.

#287415

Once again, thank you very much for your good support!