I am seeing some strange behaviour when combining a custom order with pagination when using WP_Query. The arguments for my query are as follows:

$args = array(
    'post_type'       => 'news',
    'posts_per_page'  => 10,
    'meta_key'        => 'news_date',
    'orderby'         => 'meta_value_num',
    'order'           => 'DESC',
    'paged'           => $my_page

The variable $my_page contains the current page number as extracted from the URL or set to 1 if not defined in the URL.

This query returns the correct number of results but the order is incorrect. Removing the paged parameter results in the correct order being achieved but obviously breaks my pagination.

Is there something I am doing wrong? Thanks.

Read more here: WP_Query custom order and pagination


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: