Timeline for Using wp_query is it possible to orderby taxonomy?
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 27, 2021 at 23:03 | comment | added | Ethan C |
@tehlivi Yeah, I ended up ignoring the main query entirely in case some posts were assigned more than one term. Opted instead to run get_terms() and run get_posts for each term. Added ~ 15 queries to the page load, but gets the designer the result they wanted.
|
|
Oct 26, 2021 at 21:17 | comment | added | tehlivi | @EthanC yo man thanks for your detailed response, and hopefully if anyone finds this in the future, they will find your response useful. But for myself, it certainly is hard to remember anything from 2016. I think I ended up running the array through a sort function after the query completed. I'm sure that whatever developer that took over that project after I left the company hates me. Ha. | |
Oct 25, 2021 at 20:34 | comment | added | Ethan C |
@tehlivi this method doesn't work for ordering by name because the name is in the wp_terms table. WordPress seems to cache the taxonomy terms, so even if your tax query searches by slug or name, which are also on the wp_terms table, WordPress runs those through its cached list and trades them out for IDs stored at term_relationships.term_taxonomy_id , so it doesn't have to query the wp_terms table as part of the main query. Which means neither name nor slug are included in the resulting SQL query. You have to add joins.
|
|
Jun 21, 2018 at 10:43 | comment | added | Mayra M | This is the correct answer for anyone that is interested! | |
Oct 4, 2016 at 21:52 | comment | added | tehlivi | Any idea on how to order by name instead of term_taxonomy_id? changing term_taxonomy_id in orderby_statement throws errors | |
Oct 31, 2014 at 13:48 | history | answered | Francis Yaconiello | CC BY-SA 3.0 |