WordPress is notoriously against ordering by terms. Of course it’s precisely what people need to accomplish in practice. And precisely a mess with a very clunky database representation of them (which is planned to be slowly improved over several releases to be fair).
In a nutshell the issues with your query are:
- it’s preferable to work with
WP_Query
, even if you are considerably customizing SQL - you are missing the whole third
wp_term_taxonomy
table 🙂
While I don’t think there is any truly canonical way to do it, the most reliable approach I had seen and used is covered in Sortable Taxonomy Columns post.
Related Posts:
- Get terms of posts with category with sql
- How to Query Database for posts with certain Taxonomy Term
- Return terms from multiple taxonomies using $wpdb
- wordpress mysql / wpdb ajax load more for terms help
- Get child product categories from parent product category for CUSTOM TAXONOMY archive page
- How to make an sql query to exclude everything but custom taxonomy terms in table wp_terms?
- How to permanently delete a taxonomy
- Using wpdb to connect to a separate database
- How to return number of found rows from SELECT query
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- find a random blogid across my multisite network that has at least one post published
- $wpdb->delete column values IN ARRAY()?
- Get total number of comments from posts in a specific custom taxonomy
- Inserting Post Meta From SQL
- wp_options table value
- Why does dbDelta() not catch MysqlErrors?
- What causes the “max_user_connections” warning on WordPress frontend?
- What are terms and taxonomy, how they related to post and how these three are stored in database?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Database slowdown after update to 3.4.1
- Activation hook not creating table
- Sorting taxonomy columns by meta value numeric
- wpdb_prepare with multiple or condition
- Order by custom table and multiplication
- wpdb custom post_type problem
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- How to adjust code to refresh a dropdown box with tags that are active on filtered category listing
- $wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
- $wpdb query a post type within a specific taxonomy term while ordering posts by custom meta value?
- Advanced SELECT query with condtional statements
- Selecting all posts from the children of a particular parent taxonomy
- Help With MySQL to WPDB Query Conversion
- What is faster: custom taxonomy or serialized post-meta for db retrieval? (over 60,000 posts)
- Redirecting to old domain after migration website
- Update results, Before deleting the related category [closed]
- Create table from array with prepare
- Term and sub term from custom post type query [closed]
- WordPress running SQL query to update database from form
- Sorting main query by custom taxonomy slug
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- Have working sql query… trying to adjust it to use $wpdb
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- I can’t update my data through $wpdb
- Trouble running $wpdb->query() with last_insert_id
- Different Taxonomy Values for Each Post
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- How to connect and insert data in database of wordpress?
- Add row to custom database Table and delete all rows older than 1 day
- Query custom taxonomy for category including children
- WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]
- select a single val though a table in wordpress
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Trash Bin for Categories?
- How to get related taxonomies based on a category with mysql query?
- Pull data from MySQL and add it to terms
- Unknown column ‘wp_posts.ID’ in ‘field list
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- Fill New Taxonomies
- What is my error trying to create a new table in the database?
- Writing a function for WP Cron to run a SQL command daily
- “BS_” rows in postmeta table
- Custom post type and custom taxonomy key lenght & query performance
- Using wpdb to connect to a different database is not working
- Where is the HTML-handler part in the wpdb class?
- WordPress Database Query works in phpMyAdmin but not in the code
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- How To connect to the same WordPress database with different database user
- Write mysql credentials in plugin
- Looking for suggestions on creating simple database (Help!!)
- using same mysql user with many databases
- MySQL database migration to WordPress
- Altering term_id and name via $wpdb class
- Returning info from MYSQL table via custom taxonomy
- PHP Warning: Error while sending QUERY packet
- Uploading to WordPress Database
- Putting form result in my database
- Issue with WordPress Automatically Assigning Terms to Multiple Posts
- SQL errors when querying for something with apostrophes
- Custom taxonomies not showing up in admin menu
- Search only custom taxonomies
- Custom taxonomies mixed into categories and tags in Post edit page
- Best way to redirect taxonomy terms to pages
- Optimizing function that automatically creates internal links based on post title string
- Using Advanced Custom Fields Relationship Field to select a taxonomy term
- Moving WordPress site to new domain – database import [duplicate]
- Create alphabetical Pagination for custom taxonomy?
- List Top 5 taxonomy terms based on number of post
- How to use AJAX in WordPress in MYSQL query?
- How to get attached image to taxonomy..?
- Loop through custom taxanomy in post and display custom fields from posts
- pagination not working on custom-taxonomy template
- Update multiple rows in one query
- delete term from taxonomy and assign in new one
- Understanding custom php that reads from WP MYSQL
- How to show post list based on taxonomy term?