WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[resolved] Order posts by custom field not working after 4.0 update+ (5 posts)

  1. shmox
    Member
    Posted 1 year ago #

    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

    thanks

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. elliotcondon
    Member
    Plugin Author

    Posted 1 year ago #

    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

  3. shmox
    Member
    Posted 1 year ago #

    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

  4. JonnoPrice
    Member
    Posted 1 year ago #

    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!

    thanks

  5. shmox
    Member
    Posted 1 year ago #

    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 :D

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.