Use the get_terms()
function instead:
$term_children = get_terms(
'mytaxname',
array(
'parent' => get_queried_object_id(),
)
);
if ( ! is_wp_error( $terms ) ) {
foreach ( $term_children as $child ) {
echo '
<div class="product-archive">
<div class="post-title">
<h3 class="product-name"><a href="' . get_term_link( $child ) . '">' . $child->name . '</a></h3>
</div>
</div>
';
}
}
get_terms()
can return a WP_Error object, so you need to check that it didn’t. It returns an array of term objects, so you no longer need to retrieve the objects with get_term_by()
. Since $child
is a term object, get_term_link()
doesn’t need the second parameter. get_terms()
has more options for the second parameter. You should take a look.
Related Posts:
- Display post taxonomies tree
- get_the_term_list without links in 3.1
- Inserting terms in an Hierarchical Taxonomy
- Query users by custom taxonomy and user role
- Order terms by term_order
- Get value in custom field with taxonomy [closed]
- Get second level terms of custom taxonomy
- Large taxonomy (2000+ terms), causing WordPress to hang
- Modify Term Update Redirection
- Check if current term is a child of another term
- Is there a way to import terms into WordPress?
- get_terms() doesn’t return empty terms even though hide_empty is false
- Get taxonomy name of current post
- Formating the_terms() function output
- Determine if Term has Grandparent/Great-Grandparent
- Non-hierarchical custom taxonomy using checkboxes on edit-screen -> saving issue
- Get main parent categories for a product
- show term description instead of list terms of custom taxonomy
- Looping Through Custom Tax Terms and Displaying All Posts For Each
- How to get the top most term (top ancestor) of a custom taxonomy child term?
- Contact Form 7 – Populating dropdown list with terms relative to the post
- get_the_term_list without specific category
- Listing child terms of parent term
- Display the taxonomy name of the current term
- Ordering Posts with Custom Taxonomy Terms Array
- How to create a theme template for the taxonomy “root”
- How to handle “the_terms” inside loop
- Display the Terms from a Custom Taxonomy Assigned to a Post(inside the loop) in Hierarchial Order
- How to create drop down for child categories of current taxonomy being viewed?
- Edit post meta with checkboxes on front end
- How to dynamically add custom taxonomy terms as a sub-menu of an existing menu item, using custom walker class
- Get terms ordered by post date
- How to order a list of taxonomy terms alphabetically?
- get_terms in a taxonomy template
- Custom Taxonomy Archive BUG
- Display hierarchical subterms of custom taxonomy based on depth
- Get Current Custom Taxonomy ID by Post ID
- Changing stylesheet depending on custom taxonomy terms
- ‘wp’ action hook not firing in admin and login?
- Use get_the_terms to list subcategories of custom taxonomy
- How Can I Change a Taxonomy URL Based On The Originating URL?
- AJAX response, edit tags
- List child terms if parent but show nothing on children
- Get_terms stopped working after WP 4.2
- Display Taxonomy Terms in an option tag with value being the slug
- If post has ANY term attached to it, get the first one only
- Getting Term ID from Term Name for WordPress Query
- Show only the grandchildren (using get_terms)
- Sort order by slug for looped child terms of custom taxonomy
- wp_insert_term created and set for first once only
- Updating / Saving items generated by wp_terms_checklist on frontend
- Rewrite rules for varying nested terms of custom taxonomy
- Display all posts that use a custom taxonomy
- Count Number of Posts in Taxonomy Term in Last 24 Hours
- Update table wp_term_taxonomy.count after INSERT INTO via SQL
- How can I reduce amount of ifs and else ifs in this specific block of code?
- Are term IDs unique even between multiple custom taxonomies
- What is the action hook that deletes a taxonomy term from the backend? And how to retireve the term id before deleting it?
- Get all attachments by custom taxonomy – term
- Get terms that don’t belong to current post with a shortcode
- Set term on an attachment using wp_set_object_terms and want to display the full term text but it’s showing a slug instead
- How to get posts that contain multiple terms from multiple taxonomies?
- Cannot delete or edit a single term in a custom taxonomy, taxonomy name is wrong?
- How best to store data (URLs and IDs) extracted from posts and pages using custom taxonomies
- how to get term id from current post type instead of name
- Display children category images
- Get name of taxonomies of current page
- Create alphabetical Pagination for custom taxonomy?
- export and import taxonomy terms from one taxonomy to another
- save custom term – hook create_term doesn’t work
- URL rewriting taxonomy term
- Find terms in a custom taxonomy based on the hirearchy
- Wp_query…a type of term a different div
- Show all terms in a custom taxonomy with all child terms wrapped in a ul
- Order taxonomy terms wordpress
- Show single Child Category on Custom Post
- Unable to get the Parent Custom Taxonomy Terms
- Unsetting post_tag taxonomy breaks term description for other taxonomies
- Pull data from MySQL and add it to terms
- Get custom taxonomy terms that contain posts that have another taxonomy term
- wp_insert_post not adding taxonomy (using wp_set_object_terms)
- Filter “get_terms” query
- generate random slug when adding taxonomy
- How to filter a taxonomy meta field to the ‘single_term_title’ filter hook
- Custom order of taxonomy using wp_get_object_terms and woocommerce_term_meta
- Custom post type term names with ampersand in the term name
- If page is a taxonomy do X, if is a term, do Y
- Query pages by child term
- Getting the parent terms adds additional empty markup [closed]
- Custom taxonomy list in two columns
- Tax query array terms display out of order
- Taxonomy term breadcrumb; how?
- Insert term description programmatically into hierarchical custom taxonomy
- get multiple values from $_GET from multiple checkboxes
- Get post terms with hierarchical relationships
- Unable to display the post titles in a drop down
- Taxonomy archive link from term id
- How can I get the term_id from the action hook ‘set_object_terms’?
- How to delete unused terms?
- Foreach for get_the_terms for hierarchical taxonomy don’t repeat Top Level Terms if contains multiple Second Level Terms