July 10, 2014 at 4:53 am #289309
I am wondering if it is possible to make a slight change to the way posts get ordered by title. We have posts with words followed by numbers, and they’re not in the correct order. For instance, when ordering “Blahblah 1″, “Blahblah 2″, and “Blahblah 10″, the order comes out as:
I know it’s because only the first digit in the number is accounted for, but I was wondering if there is a change that could be made to force it to recognize two or more digits.
Thanks for always giving great support,
BrockJuly 10, 2014 at 10:51 am #289406
Thank you for using our theme.
No, there is no possibility because the SQL sorting algorithm does not support this. The only way could be to hook into WP after the query and resort the result. But that is not an easy task and will make problems on pagination.
GünterJuly 10, 2014 at 3:48 pm #289561
Ok, thank you.
There may be another solution to my problem. The issue comes from the fact that I want posts to have a permanent order on certain pages, but I also need those posts to be ordered by “post date” within magazine elements.
If I use the “order” field within WordPress to order the posts permanently on certain pages, then the magazine elements will take the order “0” posts before the order “1” posts, which are taken before the order “2” posts.
Could you point to the code that determines the magazine element order, and is it possible to code it to ignore the “order” field and only order by “post date”?
If I didn’t explain this correctly let me know and I’ll try again. :)
BrockJuly 10, 2014 at 4:32 pm #289575
As far as I see in the code, the default magazine query is only by date descending. See enfold/config-templatebuilder/avia-shortcodes/magazine.php Line 366ff.
We also have a chance to hook into the query parameters, if it does not work:
line 388: apply_filters(‘avf_magazine_entries_query’, $query, $params);
Best thing you try and if you encounter problems, we can take a closer look.
GünterJuly 10, 2014 at 10:29 pm #289749
I sort of figured out a workaround with the plugin Advanced Custom Fields. I created a custom field for the posts and within the functions for the plugin I use to create these posts (it’s a wiki) I set the get_posts array to grab the custom field.
Thanks for your help!
The topic ‘order by title with numbers’ is closed to new replies.