first of all, let’s just forget query_posts
exists. there’s no good reason to use it, ever.
the best way to do this is via the pre_get_posts
action in your theme’s functions.php
. you don’t have to set any taxonomy parameters, those are already set on a taxonomy archive page, you just need meta key and orderby:
function wpa65258_tax_meta_orderby( $query ) {
if ( is_tax( 'book_style' ) && is_main_query() ) : // edit -> added is_main_query()
$query->set( 'meta_key', 'tf_book_sort' );
$query->set( 'orderby', 'meta_value_num' );
endif;
}
add_action( 'pre_get_posts', 'wpa65258_tax_meta_orderby' );
This assumes your meta value is numeric. if it’s not, change orderby
to meta_value
instead of meta_value_num
.
Then in your template, just do the normal loop:
if (have_posts()) : while (have_posts()) : the_post();
etc..
Related Posts:
- How to organize and cache additional data associated with terms?
- Display Post by taxonomy and taxonomy child
- orphaned taxonomy terms remove by sql query
- Show only, when taxonomy has posts?
- Custom WP Query: force entry for some taxonomy and have others optional
- Modify the query method when adding category filtering function to the custom post list
- Exclude posts with taxonomy term from appearing on home page query
- How can I query all post with currrent taxonomy term?
- Retrieve all term IDs of post
- Exclude taxonomy Query if post_type
- Query Two Different Taxonomies Nested
- Including taxonomy in searches
- What is this Query? and why its taking too much time? Any way to optimize it?
- How to get a query odered by N of matching taxonomies?
- How to filter the terms to a special custom taxonomy?
- How do I add tags/taxonomy to images + a query field on page to query ‘albums’ (images with same tag/taxonomy)
- Passing values by form to create a query
- How to show a hierarchical terms list?
- How to add a default item to a custom taxonomy?
- Why does get_term() require taxonomy? Are term_ids not unique?
- Automatically Assign Parent Terms When A Child Term is Selected
- WordPress – Creating multiple versions of the same single-customtype.php depending on selected taxonomy categories
- Exclude custom taxonomy from search results and archive pages
- check if tag exists in wp database
- How to update taxonomy custom field with wp_update_term()?
- How to find objects by terms
- Add Thumbnail to wp_list_categories()
- Fatal error: Call to undefined method stdClass::filter() in wp-includes\taxonomy.php on line 805
- WP native tag suggest metabox. How does it process tag id?
- Change order of WordPress tag cloud
- Let users create a new custom taxonomy entry from frontend (without creating a post)
- How to use a Term Meta Field as a link
- Embed YouTube video on category description
- Manually query posts by taxonomy with MySQL
- WordPress built-in method to extract array of term IDs?
- Is it possible to dynamically get queried term AND taxonomy?
- How to Retrieve a Taxonomy Term’s ID?
- get_terms problem : related articles
- Order By Post Type ThenBy Taxonomy
- Custom query to filter posts that have current post as a taxonomy [closed]
- Display Taxonomy Description on edit-tags screen?
- Order custom Taxomony alphabetically and reversal after clicking a button?
- Set multiple Post Terms in same Taxonomy
- WordPress Customizer – pass setting value into another control to live update drop-down choices
- Disable stored tags queries in admin page when posting a new post
- custom post type and taxonomy url rewrite without tax-name
- Show child terms of current term of the taxonomy
- Display specific taxonomy
- Taxonomy archive + query attachments = duplicate results
- Exclude posts which have any term in a certain taxonomy from the query
- How to organise this data within WordPress
- add upload image to default taxonomy
- How to get custom field value in frontend for taxonomy
- Comma separated tax terms, with “and” before last item [duplicate]
- Taxonomy Drill-Down / Plugin Help – hierarchical queries within plugin?
- Creating links to a page displaying posts from a particular category
- HTML in category name
- How to get my register taxonomy
- How can I completely hide a taxonomy term from “frontend”? [closed]
- Blogroll links sorted by category in a table
- How to relate a user object to taxonomy term?
- How to display taxonomy term custom meta (using wp_get_object_terms?)?
- How to get if child category of this category is empty?
- Adding inline help to category/taxonomy checkboxes in admin sidebar
- Automatically show ‘taxonomy’ meta box by default in Appearance > Menus?
- Declaring arguments for taxonomy
- Return single taxonomy term outside the loop
- WordPress Conditional / Multiple Taxonomy Query
- update_term_meta not working
- Getting more info about the taxonomy?
- How to make HTML select options searchable
- How to show taxonomy on front page
- Why doesn’t ‘post__not_in’ work with ‘cat’?
- I want to change the slugs of my terms dynamically
- taxonomy_edit_form_fields output after term fields
- Make/create a category for every page
- All tag/category/custom taxonomy archives 404
- Get a specific category in multiple categories
- how to display taxonomy name in do shorcode php tag
- $product->ID in has_term() not working, but manually inputting the ID works, why?
- Can I have have terms with the same slug in the same taxonomy?
- how do you get one specific term from a shortcode attribute?
- Fatal error Call to a member function filter()
- Using is_tax with multiple taxonomies
- Taxonomy pages, stop them indexing or being generated?
- Pages throwing 404 error on server load
- Custom taxonomy – query returns an error
- Display yesterday’s last post’s Custom field from Unique terms of one Taxonomies
- Special Query: Title, Terms, Content – %LIKE%
- Apply custom taxonomy archive template to children
- How can I create gallery of products and submit data for each product?
- Why does my taxonomy code display the first alphabetical term?
- Custom Taxonomy link out the loop
- get_term_link doesn’t work
- IF taxonomy archive is hierarchical THEN
- Taxonomy works in local XAMPP but doesn’t work live
- Append taxonomy url
- get_terms of specific parent (including the parent itself)
- Custom Titles for Multiple Tag Taxonomy Page
- Add new taxonomy in WP without generate any url