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
- How do I make my function add variables/values to the $post object?
- Calculate percentage of post by category
- Change comments form title on a page by page basis
- Display all posts in current category
- Get the title before comma
- “Can’t use function return value in write context” error
- Display 4 chronological posts starting with a random post
- Warning: array_pop() expects parameter 1 to be array, boolean given
- Run a filter when a walker runs
- Display fields as values in array from external SQL DB
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- What’s the uses of wp_cache_set() or wp_cache_add()?
- How to get post’s current parent term ID?
- How can I modify footer when footer.php calls to another file?
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- Function won’t run onclick using Ajax
- Where is this function’s callback getting its arguments from?
- working with term_relationships table
- List all blogs, but exclude the main site
- change the default order of posts only for specific categories
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- How to use functions [closed]
- Splitting the_content() by size?
- Updating Metadata with Shortcode
- can’t load .po file in functions.php
- WP-Bakery – Add custom colors to buttons with template colors
- Create shortcode for metabox gallery
- How can I redefine WordPress wp-content directory programmatically?
- Trim Titles Only On Some Pages
- Enqueue sripts and styles only if function is called
- ajaxurl usage for a custom function
- Open/closed function [closed]
- add a value to an external link query in searchform
- Showing the project type in HREF
- How can I clear the theme mod settings?
- Cant get theme to change footer color through theme customizer
- Get Products within Current Product Category
- WP Custom tables query
- Add text below WooCommerce short description if metabox value is true
- ACF number less than comparison not working