Support » Plugin: Advanced Custom Fields » Order posts by custom field not working after 4.0 update

  • Resolved shmox


    Hello all, i have strange behavior after updating to v4, ihave 2custom fields one is a date field and the other is list field containning numbers (for order position ex: 01,02,03…50) like that:
    custom query :

    $join .= ” LEFT JOIN $wpdb->postmeta AS pm1 ON ($wpdb->posts.ID = pm1.post_id AND pm1.meta_key = ‘post_date’)
    LEFT JOIN $wpdb->postmeta AS pm2 ON ($wpdb->posts.ID = pm2.post_id AND pm2.meta_key = ‘post_order’)”

    note here that the custom fields are : post_date and post_order

    and here is the order query:

    $orderby = ” pm1.meta_value DESC, pm2.meta_value ASC, DATE($wpdb->posts.post_date) DESC”;

    in latest v3 of the plugin all was working fine, but after updating to v4 the order is not working as expected


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


    I can reassure you that no modifications have occurred in the database from v3 to v4.

    In fact, you can roll back to version 3 without any issues.

    Perhaps the issue is not with the code you posted but with the surrounding action / filter you are using.

    Is there a surrounding code? Can you debug the current code to make sure it is running as expected?

    Debug = use print_r to print variables and then use die to end the script

    Thanks for replying, i haven’t debuged yet, i didn’t change anything in my code, i’ve just updated the plugin.

    I already roled back to v3 and it’s working as expected aka the order is working well, have reupdated again and the order is broken, strange behavior since as you mentioned above no change has be made in the database :S… really strange

    Hi there,

    Do you have instructions on how to rollback to v3? I’ve lost images on my site since updating plugin.. did not read the update instructions first (doh!)

    Also, if possible a link to the previous version plugins files very much appreciated!


    Okay i’ve understood where is the problem and resolved it :

    As i said above, i had a custom select field called post_order values in this select were like this: 01,02,03…10….etc

    In v4 of the plugin i guess 01 value (till 09) are saved without (0) so 05 is saved 5, 07 is saved 7 and so on…

    The problem is that 9 is considered greater than 10 because, but 09 is smaller than 10 (if you think as string order not integer, since meta value db field is string)

    Thant’s it , now my new post_order field starts with 10 instead of 1 so that the order is not broken anymore 😀

    PS: thanks for the plugin contributors to make it awesome for us 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Order posts by custom field not working after 4.0 update’ is closed to new replies.