The problem is with your tax_query
— the field
(database column name) does not match the terms
(database column values):
$args = array(
...
'tax_query' => array(
array(
'taxonomy' => 'state',
'field' => 'name', // <- this should be set to 'slug'
'terms' => $state_slug, // because you provided term slug
),
),
);
I.e. If you provide term slugs (e.g. foo-bar
), then the field
should be slug
; if you provide term names (e.g. Foo Bar
), then the field
should be name
.
Related Posts:
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Order custom posts by taxonomy?
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- Taxonomy posts on Archive page
- get terms that have post with custom post type between 2 values
- How to display the rest of categories on Portfolio filterable
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- 404 error PageNavi custom type taxonomy | wordpress
- Query for posts in 2 taxonomies
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Linking three taxonomies with ACF
- ‘category__and’ for custom taxonomy?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- How to make a custom taxonomy selectable in post publish area?
- Remove duplicated values from a loop
- Custom Post Type Loop within Shortcode
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Normal pages as children of my Custom Post Type
- Only show posts from a certain category?
- Display CPT posts based on specific taxonomy
- get_posts of Custom Post Type AND Custom Taxonomy
- get_attached_media() on author page not working
- Loop custom taxonomy to get lists of cutom post types?
- Custom loop with multiple taxonomy queries
- Custom post type multiple loop by taxonomy term
- List custom taxonomy specific to one custom post type
- Show a Category X’s custom post type on Category X archive page?
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Group CPT posts by custom taxonomy
- What’s the WP way to load remaining custom posts?
- Display Custom Taxonomy Alphabetically
- The loop seems stuck to a single (now deleted) post
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- Listing all term items alphabetically / sorting loop
- Display related custom taxonomy posts in sidebar
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Three Most Recent Posts, One Per Term
- get_the_title() is returning results from previous loop
- Combine multiple getEntityRecords calls
- Main query not querying any posts in custom taxonomy template
- Post loop count is not in order
- looping though custom post types and only return results in a given taxonomy
- Dynamically insert code to custom post type loop
- Pull in taxonomy field of custom post type in new query
- How to define the template for custom posts?
- get custom post type value in header.php [closed]
- get_terms() parent, child and grandchild
- List all Custom Post Type posts excluding certain Taxnomy term
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Looping through custom taxonomy and display custom post types (Custom Post Type UI)
- Create a custom taxonomy template that loops through child categories in term order?
- Loop and add Specific Categories and Products Images
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- How can I loop at a Specific Taxonomy from a custom post type?
- Fetch data from two custom post types and create multidimensional array for output to html table
- ACF – Retrieve custom taxonomy from a relationship field
- Custom archive page for custom taxonomy and pagination issue
- Create loop from selected terms in ACF taxonomy field
- Sort custom posts by date and then by taxonomy
- Custom post type paging return home page
- Is it possible to add the Gutenberg block editor to a custom taxonomy?
- How to debug failing updates for custom post type?
- WP_Query not using custom taxonomy categories on custom post type
- Combine multiple separate lists into one
- ACF meta_key and meta_value break loop
- Taxonomy shows up twice on Custom Post Type
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Show parent category and subcategory once in while loop
- List all posts associated under custom taxonomy
- Display title of all custom posts from same taxonomy term on a custom post template
- Loop to display parent categories in custom taxonomy
- Custom taxonomy template for custom fields loop [closed]
- How to show terms used only for particular custom post type. Filter creation perpose
- Display related post content and custom field content
- Best way to have one product in both rental and sale parent category
- Show posts for current taxonomy
- Custom post types not displaying per category
- Looping through custom taxonomy in one template
- Custom post type with custom taxonomy permalinks
- Loop multiple taxonomy in custom post
- $post breaking container loop
- Post data in separate divs with incrementing class using WP_Query
- Order by custom field attribute
- Display Custom Taxonomy of custom post type
- Advanced Custom Fields: query posts filtered by multiple field values
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- display custom post type from register taxonomy
- Get all active posts that are tied to a custom taxonomy for a custom post type
- Complex Custom Loop with Includes
- Create a WordPress loop that shows posts from a custom post type + filters the posts by taxonomies while hiding empty taxonomies
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template