Skip Navigation

[Résolu] Sort order set by url parameter

This support ticket is created Il y a 7 années et 5 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Marqué : 

This topic contains 3 réponses, has 2 voix.

Last updated by nathanW-4 Il y a 7 années et 5 mois.

Assigned support staff: Waqas.



I've used the shortcode provided by Caridad here:

Works well for post title, but I want to use it for date as well and it doesn't seem to be working?

So if i have the url parameter wpv-sort=date-asc set it should re-order by post date descending. It works perfectly for post title but doesn't work for post date. Any ideas why this would be?

Here's my code:

     add_filter('posts_orderby', 'my_client_order', 98, 2);

    function my_client_order($order, $q) {
     $sort = $_GET["wpv-sort"];
    if($sort == 'alpha-asc'){
        return 'CHAR_LENGTH(post_title) ASC';
    if($sort == 'alpha-desc'){
        return 'CHAR_LENGTH(post_title) DESC';
    if($sort == 'date-asc'){
        return 'CHAR_LENGTH(post_date) ASC';
    if($sort == 'date-desc'){
        return 'CHAR_LENGTH(post_date) DESC';




Any ideas on this?



Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Post Dates are not characters or strings, these are actually timestamps. I suspect the CHAR_LENGTH() may not work in this case. Please try following change for date-asc and date-desc:

    if($sort == 'date-asc'){
        return 'post_date ASC';
    if($sort == 'date-desc'){
        return 'post_date DESC';

Please let me know if it works, or if I can help you with anything related.


All sorted, thanks