Support » Plugin: Post Types Order » Conflict with ‘order_by’ => ‘post__in’ query variable

  • Resolved Hernan Villanueva

    (@chvillanuevap)


    Hi!

    I have a WP_Query class with the following arguments:

    Array
    (
        [post_type] => product
        [posts_per_page] => 4
        [post__in] => Array
            (
                [0] => 8887
                [1] => 6412
                [2] => 89545
            )
        [orderby] => post__in
    )

    These arguments should lead to a query like: SELECT wp_posts.ID ... ORDER BY FIELD( wp_posts.ID, 8887,6412,89545 ) ...

    However, your filter add_filter('posts_orderby', 'CPTOrderPosts', 99, 2); overrides the value of the orderby parameter, which returns wp_posts.menu_order, FIELD( wp_posts.ID, 8887,6412,89545 ) instead of FIELD( wp_posts.ID, 8887,6412,89545 ).

    The problem is located in line 95 of the post-type-order.php file:

    if (isset($_GET['orderby']) && $_GET['orderby'] !=  'menu_order')
        return $orderBy;

    Instead of $_GET, you should use:

    if (isset($query->query_vars['orderby']) && $query->query_vars['orderby'] !=  'menu_order')
        return $orderBy;

    like the lines above in that same file.

    By using $_GET, the plugin kills the orderby => post__in feature of the WP_Query class.

    Thanks for your attention! I really appreciate it!

    Hernan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author nsp-code

    (@nsp-code)

    Hi,
    You can include the ‘ignore_custom_sort’ => true within your query arguments.

    Thanks

    Thanks for your reply!

    I’m aware of your query argument. However, I believe that does not address my question. I did not open this topic for support; I did it to report a potential bug.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conflict with ‘order_by’ => ‘post__in’ query variable’ is closed to new replies.