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
{}withifstatements, 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
- 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?
- Counting number of posts with Category B in Category A
- Custom archive page based on array of categories and tags
- Function to check if author has posted within the last x days
- 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
- Get posts using WP_Query
- Finding post content that begins with a specific character
- tax_query shows no results if nothing is selected
- Best practice custom function, where to echo the variables?
- How to get user_id from wordpress database inside ajax function?
- Setup of taxonomy term template pages
- How to do a query on custom taxonomies that is uncategorised?
- Order taxonomy terms in alphabetical order
- Query Custom Post Type Order By Taxonomy Field
- Query post from all category with same tag on 1 pages
- Query with custom taxonomy not working
- Multiple Loops Inside a Function
- showing all search result in one template
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- List custom taxonomy terms sharing posts with a term from a second custom taxonomy
- Query custom post type by custom taxonomy (category slug)
- How to Filter Posts by Custom Fields?
- Display posts from only one post form in custom query and exclude in main query
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- Show posts from a custom taxonomy on a page
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- wp_query for multiple cities (multiple values in a metabox)
- Query with relation and one without relation using multiple taxonomies?
- meta_query not working as expected
- Display custom tags on pages that have a specific page parent
- wp_query args adding muitiple tax_querys
- how to access query string in wordpress?
- Merge two search functions for custom post type
- Filter Custom Taxonomy Posts
- WP_Query args to show posts from specific custom taxonomy
- Make a SQL query with wpdb in WordPress
- Using custom taxonomies in a query
- get term id from term name
- WP_Query to output chosen term and posts with no term assigned
- Exclude authors IDs from WP_Query
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- Check if a post has term inside loop
- How do I fit WP_Query arguments into a function?
- Create a notification for post field
- Add URL Rewrite Rule To WordPress
- How to get posts by category and by choosing a taxonomy term?
- How to restrict search on a certain page to only return results against custom taxonomies?
- Query Taxonomy By Page Title
- WordPress dynamic AJAX query
- Custom Taxonomy Breaks Pages
- relation OR instead of AND – Filtered term ID’s in loop
- get_the_terms has strange result since version 6.0
- How to display posts from custom post type category(custom Taxonomy) wise?
- Show X taxonomies of the latest published posts
- set object terms after some some time of published post – functions.php
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- Custom Taxonomy – Modify Function to Get Child Category
- wp_set_object_terms() custom taxonomy not working correctly when using insert post
- WordPress – Form does not filter the results of taxonomies
- How to get taxonomy image attached to a Post Type WordPress
- Custom query for custom post type not getting correct post ID
- 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
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- 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
- Save query in function for custom gallery
- Taxonomy Terms That Don’t Exist Display Results
- Adding additional taxonomies to wordpress taxonomy page
- 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
- What argument does my function need to echo get_results() query results
- Query Top Set Custom Taxonomy In Given Timeperiod
- Rewrite rule pagination on different url levels
- Select posts wich has no relationship in custom taxonomy
- How to get hierarchical number of custom taxanomy
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- Get newest value of an array
- Filter custom post type by custom taxomony
- ordering and optimizing functions
- 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
- Display Featured image from custom post type category (custom taxonomy) wise
- Excluding a category from frontpage but not from WP_Query
- Filter on one post type with taxonimy and get other post type
- has_term not returning anything