Try to change $cat_name by the category ID.
$term_name = get_query_var('taxonomy'); // current taxonomy
$cate = get_queried_object();
$cat_id = $cate->term_id; // current category ID
echo $term_name;
echo $cat_id;
$wp_query = new WP_Query(array('post_type'=>'st_ai',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => $term_name,
'field' => 'slug',
'term' => $cat_id,
)
)
));
if ( $wp_query->have_posts() ) {
echo "good";
}
?>
Related Posts:
- WP Query Args – Title or Meta Value
- WordPress Pagination Not Working – Always Showing First Pages Content
- Whats the difference between post_limits and pre_get_posts?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Query WooCommerce orders where meta data does not exist
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- What exactly does the ‘s’ parameter search for in WP queries?
- Query all posts where meta value is empty
- get_posts not finding argument: post_name
- get query’s query string
- Show only oldest post by author
- Revolution Slider Orderby Two Custom Fields
- Calling a custom excerpt function in a local loop
- wp query by search in titles only & put the posts in loop
- Get random terms
- Dynamically Override Fancy Title – Part II
- Count posts returned by get_posts in external PHP script
- How to run query inside a class with namespace?
- List the 5 most recent child pages
- Meta-value query
- Modify existing query and change order of posts
- Why does the_content not work like others for a set post id?
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Creating a custom search for a specific post type
- How to add post_distinct filter to WP_Comment_Query?
- WP_Query Group by Author and Order each group DESC
- List only posts from specific category on category page
- new WP_Query(), have_posts() return false in user_register hook
- How to filter, restrict and return posts based on custom user meta information
- Masonry, WP_Query & paged – first page repeating, second page not loading
- Query posts intersecting tags and categories
- WP_Query ignoring tax_query when is_singular
- WP_Query() order by post content lenght?
- REST API: Limit Read Permissions for Default Endpoints
- Excluding pages in WP_query using ACF
- How to sort post by custom table value
- Pagination on static Posts page
- WP_Query : Search and Filter Using custom field AND/OR custom taxonomy
- Query all posts if multiple meta key don’t exist
- WP_Query with rewind_posts creates duplicate titles
- Is it safe to access the underlying mysqli object from \wpdb for custom queries?
- wp_query to print posts if have X custom field value
- Rewrite gets completely ignored
- Check for the main query from the template
- How do I turn these values from MYSQL into an array
- get_posts() and global variables
- Use Ajax To filter posts?
- Should $query-> be used with conditional tags?
- Get user posts with custom WP_Query on author.php
- Hide products in uncategorized category from search results
- Is it possible to add relation between meta_query and tax_query?
- PHP – Loop custom post type categories within jQuery Tabs
- How order posts from category by date and comment count?
- Get a list of ACF Repeater-Fields as array
- Custom navigation : show posts in sets of 4
- Get query results with a page title
- Show single posts date, in a page of posts
- WordPress WP_Query compare not working?
- How to filter multiple queries with search?
- Compare “Main” post ID to ID inside wp_query loop
- WP_Query Class custom field parameters
- Attempt to display site authors in a carousel – User Image not Outputting inside li tags
- problem with the loop
- How to get all user posts from two post types in wp_query
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- WP_Query for distinct meta values
- Group Product Types
- Facing problem with tax_query results
- pre_get_posts pagination not working
- Prevent Duplicate Post Counted by Query
- Save queried result into database
- sanitize_post() is not sanitizing Post Object
- WP Query by variable custom field
- WP_Query multiple value not working
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Translating WP query into to SQL query
- How to get top rated posts using wp query?
- Unusual high query of user meta data
- TAG Query showing only 1 result
- Tax_Query not working – connecting to second wordpress database
- How to search CPTs in draft using get_page_by_title()
- WP Query Meta Query
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Archive – Show Page Month Headers
- Get newest value of an array
- Return a single custom post from multiple meta queries
- ordering and optimizing functions
- Why does order ASC break offset in WP_Query?
- new WP_query using custom fields
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- query post based on comparison
- Dynamically create array from page title
- Ordering Custom WP_Query loop by meta key value with pagination
- wp_pagenavi on WP_Query using customfields
- paginate_links() on page (shortcode output)
- WordPress Query Returning Every Post
- How to write a query-function as a query-shortcode?
- shortcode with $atts with strange results
- WP Query returning all posts when Meta_query is null