The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WP posts per page on custom post type Reply To: WP posts per page on custom post type


I have one follow up question for you.

Can I turn $query->set() into an array? I’d like to add order and orderby to it:

function get_all_town_posts( $query ) {
  if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'towns' ) ) {
    $query->set( array(
            'posts_per_page' => '-1',
            'orderby' => 'name',
            'order' => 'DESC'
add_action( 'pre_get_posts', 'get_all_town_posts' );

When I try that, it returns an error:

Warning: Missing argument 2 for WP_Query::set(), called in /.../www/wp-content/themes/dst-fp/library/custom-functions.php on line 36 and defined in /.../www/wp-includes/query.php on line 2369

Warning: Illegal offset type in /.../www/wp-includes/query.php on line 2370

Notice: Undefined variable: value in /.../www/wp-includes/query.php on line 2370

In the first error, line 36 would be line 8 in my first code example.