Nothing. You shouldn’t need to set the post type. Your taxonomy archive is presumably already querying the correct post type.
function customize_customtaxonomy_archive_display ( $query ) {
if ( $query->is_tax( 'country' ) ) {
$query->set( 'meta_key', 'start_date' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
}
}
Note:
$query->is_main_query()
is redundant when checking$query->is_tax()
, because (as far as I’m aware) secondary queries can never be a taxonomy archive.- Setting the posts per page has nothing to do with sorting, so I’ve omitted it.
- You need to use
{}
withif
statements, otherwise the condition will only apply to the next line. The original code you’ve copied will apply that sorting and posts per page value to all queries. Even if you only have one line, omitting the brackets is considered poor practice.
Related Posts:
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- WordPress tax_query “and” operator not functioning as desired
- Custom taxonomy query broken after upgrade to 4.4
- Show posts without term
- How to add taxonomy filter on the query fly?
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Query two taxonomies via URL or link?
- Pagination custom query
- Order by two meta keys
- Counting number of posts with Category B in Category A
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Custom archive page based on array of categories and tags
- Function to check if author has posted within the last x days
- Select posts wich has no relationship in custom taxonomy
- Shortcode returns escaped HTML tags
- Calling a custom excerpt function in a local loop
- How to get any tag ID
- List taxonomy terms plus their latest post ordered by post date
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Dynamically Override Fancy Title – Part II
- query posts in functions.php and update a field
- Filter and list posts of a custom taxonomy
- Get posts using WP_Query
- Finding post content that begins with a specific character
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- tax_query shows no results if nothing is selected
- How to Modify Taxonomy Archive Page with Search Parameter?
- How to check if logged in user have pending custom post?
- Custom WordPress post query for displaying time-released content on website
- Related categories order posts by category
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- WordPress – Form does not filter the results of taxonomies
- WP Query for all events prior to current date
- How to get taxonomy image attached to a Post Type WordPress
- list all post who have mutual taxonomy as current taxonomy!
- Custom query for custom post type not getting correct post ID
- Finding post ID dynamically on click
- how to move a page from one drop down menu to another drop down menu
- Show one post of each custom taxonomy
- Query WP Posts, then list the taxonomies from those posts
- How to upload 3 attachments to current post?
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- Displaying posts from sub taxonomies only
- Global page ID variable empty error
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- Optimal way to make tags in tax_query optional?
- How to define a custom hierarchy for terms?
- WP_Query & shortcode : Return 3 articles from a category WordPress
- My entry results are not consistently alphabetized
- Get post Number with local loop and template
- Save query in function for custom gallery
- Taxonomy Terms That Don’t Exist Display Results
- Adding additional taxonomies to wordpress taxonomy page
- I cannot get tax_query in get_posts() to work with custom taxonomy
- How to create page that lists tags by initial letter?
- Seach and categories not working when ignoring sticky posts in main loop
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Calling a function with WP_Query only ever brings the first result
- What argument does my function need to echo get_results() query results
- How can I get all the posts that are related with a specific taxonomy term?
- How to combine nested tax_query logic with other nested query logic?
- Query Top Set Custom Taxonomy In Given Timeperiod
- tax_query not working for taxonomy slug
- Rewrite rule pagination on different url levels
- Fetching $_POST from Page Template into functions.php
- Select posts wich has no relationship in custom taxonomy
- Custom query for tag and custom tag from 2 post type
- How to get hierarchical number of custom taxanomy
- Declare inline background image in functions.php
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- WP_Query to show post from a category OR custom field – Not 100% answered
- Get newest value of an array
- Filter custom post type by custom taxomony
- Page displaying 1st post from a range of custom tax?
- WordPress WP_Query Array Custom search via taxonomies
- ordering and optimizing functions
- Why WP_Query in functions.php is not working when get_posts works?
- query_posts problem – need help
- Adding css tweak based on page template
- How to write a query-function as a query-shortcode?
- tax_query not working properly with get_posts
- 1500+ duplicate queries via get_option function (query monitor)
- Give attachments an archive page, and exclude unattached ones
- Variations as Single Products [closed]
- Custom Taxonomy in custom REST API search
- I’m trying to get posts under a custom taxonomy but I don’t know what I’m doing wrong here
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- Display Featured image from custom post type category (custom taxonomy) wise
- Excluding a category from frontpage but not from WP_Query
- Adding a language rule and displaying posts with a custom taxonomy term on its archive page
- WP_Query on custom taxonomy -> Location and Activity
- Filter on one post type with taxonimy and get other post type
- Include custom post type that matches taxonomy field in another custom post type
- Showing all posts of the current custom taxonomy on archive page
- Include posts with a specific custom taxonomy term in author page
- wp query order posts by custom taxonomy doesn’t work correctly
- has_term not returning anything