Support » Fixing WordPress » Sort post via term
4 years, 4 months ago
How would i sort the post via term using the class WP_Query?
You will not be able to do this if posts are assigned more than one term. How would you know which one to use for the sort?
If your posts are assigned only a single term, it may be possible to do this using filters to modify the query. Here is an article that shows example filters: http://wordpress.mcdspot.com/2010/05/30/filters-to-modify-a-query/
You would set the global variables to the clauses necessary to change the query before issuing the call to WP_Query, and reset them to blank after the call.
Would you give me an example for it and how the code looks like? Sorry but im not as expert in wordpress like you.
For example i do have a term word ‘foo’ how could i use the wp_query class to achieve this.
Is ‘foo’ the term, or the taxonomy? If it is a term, there is no need to sort on it because you would select all posts with that term.
If it is a taxonomy, here is a pastebin with sample code to sort by the terms of a taxonomy.
No…no…no… It’s my fault. Not specific term btw.
What i really mean is to sort all post via there term.
See the pastebin link that I posted earlier for some sample code.
It throws me an error. Do you have another one.
That code cannot be used ‘as is’. It must be adapted to your theme. It is only meant as an example.
The exact coding will depend on your theme.
Nope. The error is thrown by core wordpress php file which is query.php
I just copied the code and tested it with no errors. Please put your code in a pastebin and post a link to it here.