I may be missing what you’re looking for but you never actually echo the cat_ID
in the li and there’s no reason to assign $cat->cat_ID
to $cat_id
.
Additionally, I think you could just as well use something like this to get the category id (or ids) to display the current category(ies) of the current post. (using $category[0]
will give you the first category)
<ul>
<?php
$category = get_the_category();
foreach ( $terms as $term ) { ?>
<li id="tools-<?php echo $category[0]->cat_ID; ?>"><?php echo $term->name; ?></li>
<?php } ?>
</ul>
Related Posts:
- exclude multiple terms using get_terms() function
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Allow authors to post only in categories they create in WordPress
- Add custom field to attachments in a specific category
- How to Populate the list of custom post type categories
- Php string not working in WordPress Functions.php [duplicate]
- Problems with function on function.php
- Use template for posts with a particular category grandparent
- Check if Product is in a Specific Category in Functions.php
- Woocommerce – remove product from category
- get_the_terms – only top level
- Query all posts of a custom taxonomy term
- get current product name in functions.php
- get post based on category chosen in drop down – The ajax method
- Swapping wp_dropdown_categories function with wp_category_checklist
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to pick the default selected value in wordpress dropdown?
- Get page that displays all children of taxonomy parent
- How to show only subcategories in parent category not parent category?
- Dilemma of Populating all the categories in a drop down list
- Edit the_category (); for a hierarchical display
- Displaying posts based on category
- Hierarchical taxonomy list with modificated term links
- Use get() method to grab all categories and output inside another method
- How to get current post category details inside “loop”?
- Show all tags within a category?
- Post not populating for custom post type based on category selection
- Listing titles and custom fields of entries within subcategories
- WordPress custom taxonomy
- making php value numeric
- Taxonomy term description with style, only if the description exists?
- How to change the author box selection on a post to a custom taxonomy
- How to hide a child category and show his parent category
- Dropdown category field inside repeatable metabox
- Display Visual Composer shortcode if a post belongs in specific categories
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- Get parent category name when only child category is applied to a product
- How to move a post from one category to another
- Notice: Undefined variable
- Hide a specific category title from displaying on site
- Populate Posts based on category selected using AJAX that means without page refresh
- All categories options or All categories not Populating
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- PHP get_category() function redeclared
- str_replace not preserving whitespace
- Custom Taxonomy as Link
- Limit Taxonomy Parents
- Saving category as insert post
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Displaying categories
- How to insert the first letter in uppercase [closed]
- How do I change the Go To Categories link in the term_updated_messages
- Display terms on product page with shotrcode
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- WordPress different custom tag being displayed in on tag list
- Get category name of current post (CPT UI)
- Exclude a category ID from the following function
- Help with get_categories code
- Is it possible to go to the next post in the same category?
- Placing raw HTML inside a WordPress shortcode
- How to use return in my custom function instead of echo
- Get category name from custom loop and echo it once
- Differences when using the the_time and the_date functions
- Create Logout Link WordPress Admin Menu
- Display all categories including sub categories
- Word Count Function Preventing Permalink Editing
- Add a Second Menu to a theme that only support 1 menu
- How to speed up a wordpress function with multiple loops?
- How to Display Image Meta underneath EVERY image in EVERY post
- Custom excerpt function re-factoring
- PHP can I add line numbers to file_get_contents()
- Adding tawk.to code just before body tag on functions.php file
- How to change a public function inside a class of a plugin?
- syntax issue on php 7.4
- How do I fetch all comments per post via WP REST API?
- How do I publish only one page to production after making changes on staging?
- Have CSS Class Added with `is_page()` WP function
- Slide in Panel WordPress Post
- Changing Woocommerce flat rate every nth number of items
- Shortcode content output but not in correct place
- Use wp_get_recent_posts with search term
- Weird problem happening with custom taxonmy when creating/updating posts
- Convert all images to PNG on file upload
- How to restrict page access to logged-in users?
- Remove query string specific key value
- is_page “range” for if statement?
- Calculations in functions.php [closed]
- If search results empty then execute certain code
- Shortcode return function with link href inside PHP
- Can’t load WP function into external function
- Custom category code not showing all posts
- Count the number of times the search form template gets included on a page
- Get Custom URL For Custom Taxonomy
- PHP code inside shortcodes
- Limiting woocommerce line_total decimal length
- get_terms orderby numeric
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Run a filter when a walker runs