I’m only going to focus on the category listing you have in the code above and ignore the custom query since that’s not what you’re asking about.
<?php
// I assume the custom taxonomy slug is "basics"
$categories = get_the_terms( get_the_ID(), 'basics' );
// get_the_terms returns false, a wp error, or an array of term objects.
if ( $categories && ! is_wp_error( $categories ) ) {
foreach ( $categories as $category ) {
// get_term_link requires taxonomy slug as the second parameter.
echo '<a href="' . esc_url( get_term_link( $category->term_id, 'basics' ) ) . '" title="' . sprintf( esc_html__( 'View all posts in %s' ), esc_html( $category->name ) ) . '">' . esc_html( $category->name ) . '</a> ';
}
}
?>
I adjusted a few details. Inline comments should provide some detail. I also added escaping to the output since this is a best-practice.
Related Posts:
- get_posts assigned to a specific custom taxonomy term, and not the term’s children
- How can I get only parent terms?
- How to add images to taxonomies?
- Read-only taxonomy (user can assign term but can’t create or edit existing terms)
- Can you add the visual editor to the description field for custom taxonomies?
- Adding Category/Tag/Taxonomy Support to Images/Media
- get_terms does not return any results for my custom taxonomy?
- Order terms by term_order
- Large taxonomy (2000+ terms), causing WordPress to hang
- How to display warning on post editor when trying to add new term to custom taxonomy?
- How do you remove a Category-style (hierarchical) taxonomy metabox?
- Is it possible to have a taxonomy archive that lists taxonomy terms?
- 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
- You are not allowed to manage these items – bug introduced in 4.4
- Get taxonomy name of current post
- Custom metabox for menu administration page?
- Remove Custom Taxonomy Base
- How to pass posts_per_page and paged params query vars to custom taxonomy archive urls?
- Exclude Custom Taxonomies
- How to get the top most term (top ancestor) of a custom taxonomy child term?
- Get custom category name from ID
- Retrieve custom taxonomies
- why do drafts return as part of wp_query?
- Populating dropdown menu with hierarchical taxonomies
- Taxonomy archive template to have conditional logic for displaying child categories
- How can I allow a custom taxonomy for certain roles?
- Reverse traversing taxonomy based on term_id
- Specifying a size when displaying an image associated with a taxonomy through ACF
- ‘wp’ action hook not firing in admin and login?
- How can marge these loop code?
- How to check if do_shortcode will be execute directly in a template php file
- I used the Tax-meta-class by bainternet but i still can’t get it to display any of the results.
- Display all posts for taxonomy term across multiple custom post types
- Getting Term ID from Term Name for WordPress Query
- Show only the grandchildren (using get_terms)
- Custom permalinks with hierarchical taxonomy – getting PHP warning
- Taxonomies on custom taxonomies
- Get list of taxonomies associated with Subscribers
- How to join result of different taxonomies?
- wp_insert_term created and set for first once only
- Show all taxonomy’s terms’ posts having another taxonomy’s term in common
- Render P2P metabox per taxonomy term
- where is the 4th taxonomy terms? taxonomy terms is disaapearing in the loop
- Replace taxonomy permalinks
- How to rename custom taxonomy URL with extra words
- Separate tags with semicolon
- Adding content to custom taxonomy category pages
- Display formatted list of taxonomy terms with last seperator different
- Are term IDs unique even between multiple custom taxonomies
- How to customize custom taxonomy url?
- What is the action hook that deletes a taxonomy term from the backend? And how to retireve the term id before deleting it?
- Display a colour of custom taxonomy on the page
- How can I get a paginated list of custom taxonomy tags with posts?
- Add attribute taxonomy through code don’t appear in admin product page
- Search only custom taxonomies
- Save values generated via API as taxonomy terms
- URL rewriting taxonomy term
- How to avoid foreach error WebDevStudio’s WDS_Taxonomy_Radio taxonomy metabox class?
- Show all terms in a custom taxonomy with all child terms wrapped in a ul
- Order taxonomy terms wordpress
- Query Multiple Custom Taxonomies
- WPML taxonomies not translated
- Why do my quick edits for custom taxonomies not show on the post frontend?
- WordPress REST API – get custom taxonomy category posts
- Pull data from MySQL and add it to terms
- Taxonomy and Page Slug Same
- Tracking the name of a custom taxonomy
- Filter language in Polylang for custom taxonomy
- Group posts in a category based on tags in custom taxonomy
- Multiple Custom Taxonomy Rewrite
- use apply_filters return taxonomies custom post type
- Dropdown (with onChange) with custom taxonomies
- Custom column into custom taxonomy (img tag with slug-name as file name)
- ACF Custom field not showing in Timber Taxonomy page
- How to get a terms and posts associated with another term?
- Displaying subcategories and then posts in taxonomy template
- How to use two same taxonomy in same post differently?
- How to show one post content in another post content which has same terms?
- How to set “manage categories” capabilities on a post type taxonomy but not on the general categories?
- Custom taxonomy name not being translated in post manager page
- Include attachments with a custom taxonomy in search
- Can I use multi (sub) levels of relation (AND | OR) on custom query?
- Avoiding stripping of HTML in Custom Taxonomy Meta Field
- Advanced AND tax_query in sidebar with 2 taxonomies
- How to update WordPress custom SQL Select query for custom taxonomies so that syntax is correct?
- Display term description on hover using get_the_term_list
- Alternative for is_taxonomy() to workaround theme’s default sidebar
- Can I use get_term_children to show child terms if they exist and show something else if they don’t?
- Displaying the custom taxonomies side by side on the admin dashboard
- Display woocommerce product_cat child terms with thumbnails
- Head Code for Custom Taxonomy
- How to add a custom page template selector to a custom taxonomy?
- Adding new terms to custom taxonomy
- List posts grouped by children of a custom taxonomy
- Add Gutenberg editor to edit taxonomy (category) page
- Why my archive title isn’t showing?
- Two taxonomies with the same slug
- Hook function when taxonomy terms change