So, I have a custom post type, ‘properties’.
I’m using archive-properties.php
, and need to set some parameters on the $query
.
I don’t want to use new WP_Query
since I ran into some issues where a pagination plugin was trying to paginate the $query
that already existed since we were on an archive page, if that makes any sense.
So now my problem is, if I set posts_per_page
to 2
for example, and login to the backend, its only showing 2 posts.
So I need this to change the query on the frontend, but not the backend. I don’t know what to include in the if statement.
function set_query_parameters($query) {
if( is_main_query() && is_post_type_archive( 'properties' ) && !$_SESSION ) {
$query->set('posts_per_page', 12);
$query->set('orderby', array(
'date' => 'DESC',
));
}
return $query;
}
add_action( 'pre_get_posts', 'set_query_parameters' );