• Hi there,

    There’s an issue with your plugin forcing itself into every WP_Query, including custom ones where you specify an ‘orderby’ value.

    The issue is with line 132 inside class.cpto.php. It needs to be:

    if ((isset($_GET[‘orderby’]) && $_GET[‘orderby’] != ‘menu_order’) || (isset($query->query_vars[‘orderby’])))

    This is to allow for custom WP_Query order values.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Maya

    (@tdgu)

    Hi,
    Actually i’am not sure that will work, imagine if there’s an ‘orderby’ => ‘menu_order’ this will be ignored too.
    However, keep in mind that using Autosort On, all queries will be changed and forced to use menu_order. If Autosort is Off, only queries which include a ‘orderby’ => ‘menu_order’ returns objects per menu_order.

    So it’s a matter on how you set-up the Autosort on your site.

    Many prefer to keep that On. If so there are still ways to make a query to ignore the forced ‘menu_order’ e.g:

    • Add a paramether to your custom query ‘ignore_custom_sort’ => true
    • Use the filter ‘pto/posts_orderby/ignore’ and return TRUE . This takes 3 arguments $ignore_status, $orderBy, $query
    • You can temporary disable the plugin ‘posts_orderby’ hook until query processing completed

    Thanks

    Thread Starter wpthemesetcom

    (@wpthemesetcom)

    Hi,

    Actually i’am not sure that will work, imagine if there’s an ‘orderby’ => ‘menu_order’ this will be ignored too.

    I would disagree with the above statement as I have just tested this and it’s working as expected. The suggested change means is that if there is a custom WP_Query and if that query has the parameter ‘orderby’ then use the custom parameter instead of the forced autosort.

    Your proposed alternative methods are also great, but it wouldn’t hurt to add a fourth option to ignore the forced ‘orderby’ just to avoid other developers from pulling their hair out ??

    Thanks

    Plugin Author Maya

    (@tdgu)

    Hi,
    I see your point and i agree. However keep in mind that 99% of plugin user don’t have any php knowledge so they prefer to use an Autosort functionality than modify code to apply the menu_order. Many custom queries include an ‘orderby’ argument using date or id, but majority need to use menu_order as value.

    Thanks

    Thread Starter wpthemesetcom

    (@wpthemesetcom)

    Hi there,

    I do agree with you, but my point is that a plugin should never impede the core functionality of WordPress to avoid other developers having to hack around said plugin in order to continue with the development process. It’s simply bad practice.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Forced ‘orderby’ breaks WP_Query’ is closed to new replies.