$terms
is an array of terms, so PHP doesn’t know what you mean when you say $terms->slug
.
With foreach, you’re iterating through this array. If you only care about the first element, you can simply use $slug = $terms[0]->slug;
. This will get you in trouble when there are no terms, though, so you will want to make sure you only operate that if there are terms, with something like
$queryparams = array("post_type" => "mycpt");
if(count($terms)) {
$slug = $terms[0]->slug;
// modifiy your queryparams here
$queryparams["tax_query"] = ...
}
Related Posts:
- What is ‘term_group’ for ‘order_by’ in get_terms()?
- Display all the subcategories from a specific category?
- How to get_term_children output in alphabetical order?
- Correct use of get_the_terms()
- Get multiple term IDs by slug, and then exclude them in get_terms
- I have a term_taxonomy_id — is there an API call to get the taxonomy?
- wp_set_object_terms creates relationship to REVISION?
- How do I access a single term from a post?
- Prevent Selected Terms Rising to the Top
- How to update incorrect post count in taxonomy?
- Term begins with a letter
- get_terms() but with additional dimensions?
- how is it possible that using wp_insert_category throw a fatal error?
- How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero
- Get post terms for multiple posts at once?
- wp_update_term: How could i update the “name”?
- Check if an array of posts has posts from a specific category
- Get only one product category woocommerce
- get_terms() order by term_meta
- Difference between get_category, get_term_by and get_categories
- get_terms() for custom taxonomy related to another taxonomy
- get_terms from registered taxonomies not working
- What is the term shortlink structure?
- Invalid argument supplied for foreach() in search.php
- Do I have to set parent when set post term?
- How do I determine if a certain term is in an array?
- get_terms ‘number’ parameter does not appear to work
- Question with get_the_term_list
- Group child category IDs based on their parent category
- Custom Template for one Taxonomy Term
- Unset actions for terms parent only
- Create / Close Div in Array [closed]
- Getting all categories even with no products under it?
- import_id parameter for wp_insert_term to create custom ID for category
- Programmatically add posts add and assign postmeta and assign terms
- When using the get_terms and trying to order the terms using the ‘order’ and/or ‘orderby’ does not work
- get_terms – name__like a number
- Why does wp_get_object_terms add a period after terms are output?
- How to apply comma separation,strip_tags and orderby to wp_get_object_terms
- wp_set_post_terms is assigning only the last of several terms to a post
- wp_set_object_terms not working inside loop
- Leveled – Terms foreach
- Add Taxonomy Description with wp_set_post_terms
- get_the_terms() not returning expected result
- Add class to first post queried
- wp_insert_post() does not support variable
- Missing term_id value
- Get the ID of category page with or without any posts
- WordPress Term for Custom List
- array_replace throwing php_warning but working anyway
- Get current term in single.php
- How do I print a term list but alter the link text?
- Polylang : Display term archive even if no posts
- Echo term slug op post on archive page
- Display posts belonging to child term
- Get get_terms alphabetically
- Temporarily un-associate term for an amount of time
- How to get term by name with parent id?
- How to extract one field from wp_get_post_terms objects?
- CTP – check for value inside objects
- If product is in sub-category show code
- List posts by their custom taxonomy term, with a condition
- Set unique term_id from custom meta keys
- Trying to use wp_set_object_terms while supplying an array for both term id, and texonomies
- Get fuzzy matches from get_term_by
- Problem retriving the post type category
- get_terms_args ordering by meta key not working
- Cannot retrieve categories for post in The Loop
- How to show posts from category A on category B page?
- How to use category slug to echo a page’s content with the same slug
- Can we apply hide empty to get_the_terms?
- PHP Warning: Attempt to read property “slug” on bool in tax query
- wp_set_object_terms doesn’t work
- How to use get_terms() returning only the terms that have posts with a certain custom field value
- get_the_term_list( get_the_ID() label formatting?
- I can get posts in all categories. But I want to get the custom post type I created
- how to show all categories by get_terms
- How to display taxonomy order child, parent
- Update term_id to new value wherever it exists, to combine the two.
- wp_get_post_terms – Do Not list Duplicates
- Flush rewrite rules after a term is edited
- How to show term child only if has a post
- Wrap custom terms loop
- A Comma Between Each Items Except the Last One with get_the_term_list [duplicate]
- get_terms not working when child_of is used
- modify strip_tags function to use term slug instead of term name
- Getting Term_id – Taxonomy Metadata plugin
- get_terms Parent Tags
- Get term_taxonomy_id from return of wp_insert_post
- Function to delete a term when a custom post with the same slug is trashed
- Get object terms with no children?
- How do I assign a custom post to all terms in a custom taxonomy?
- Conditional output based on taxonomy ID of custom post
- is action hook not working on quick edit?
- WordPress emails error regarding the argument type even if the type is correct
- list taxonomy terms in current post / current category
- Relate term to term?
- How can I filter get_terms with post meta
- Unable to import term_meta in wordpress using wp_cron
- How can I replace the values in WP_Term?