Most probably the term was not found and $current_term
returned as false
:
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$term_id = false === $current_term->term_id ? null : $current_term->term_id;
According to the docs, get_term_by()
return values are
Term Row (object or array) from database. Will return false if
$taxonomy does not exist or $term was not found. Othewise returns
object (by default) or array of fields depending on $output parameter.
Output the $current_term
value and see if it is false
:
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
var_dump( $current_term );
$term_id = $current_term->term_id;
Related Posts:
- Return category slug / title from category ID
- Add custom taxonomy under the category title
- How to “group” (categorize) the Pages together?
- How can i add service category here? [duplicate]
- How to Manage and link certain custom taxonomy?
- Converting Categories (with ACF fields) to custom taxonomies
- Is There a Difference Between Taxonomies and Categories?
- Check if a post is in any child category of a parent category
- How to export and import taxonomies (category, tag and/or custom taxonomy) and their terms
- Control term order on a per-post basis
- How can I add the featured image functionality to a custom taxonomy?
- Share one taxonomy across multiple blogs in 3.0 [duplicate]
- wp_update_nav_menu_item() to insert categories
- Admin Panel – Disable Moving Selected Terms To Top of Metabox
- How to make custom taxonomy check boxes like ‘Categories’
- Create terms when registering taxonomy?
- How to create non-unique sub-category slugs?
- adding custom fields to next and previous post link
- How to get next previous category in same taxonomy?
- Display only deepest category on a single post?
- How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?
- Wrap a chosen category name with div
- wp_list_categories, Add class to all list items with children
- Getting WordPress custom taxonomy/category?
- Display empty taxonomy terms with get_terms()
- Connecting WordPress gallery to custom categories (taxonomy)
- Get term by slug in Gutenberg
- How to query posts from specific authors and categories using WP_query?
- Filter out posts before display category count
- New categories are now going to 404s
- How to put enctype=”multipart/form-data” in categories form?
- “Reversable” and “Re-useable” Subcategories (or other taxonomic structure)
- Get multidimensional array that reflects category hierarchy
- List Terms in Category
- How to get category URL with the slug?
- Taxonomy filter all children
- Display Slug instead of Name
- Force a user’s posts category
- Search Posts / Pages with multiple options?
- ACF: Display category name using taxonomy field
- How to filter out Categories for specific post types on WordPress Admin?
- need to add custom field in more products
- Taxonomy name repeating when showing 2 posts from each category
- New Categories Not Shown In the Post Edit Page
- How to change a post category when the ACF datepicker Field is today
- Shortcodes not working in category or tag description
- Filtering multiple categories via the URL
- Display specific categories by ID
- Display Posts Loop for each parent and for each Child
- Listing Texts of Which Custom Field is Null
- Why don’t posts show up in my categories on the frontend?
- Flat category URLs but retaining hierarchy?
- How many categories can WordPress handle before performance suffers?
- Custom taxonomy template for categories
- How to query categories with Advanced Custom Fields?
- Wacky taxonomy in wordpress
- How to add custom color fields to the category edit page?
- Include WooCommerce product to all child categories
- Question on using custom structures for categories
- echo get_post_meta of all post in a category to fill up a select field
- WP REST API not retrieving all categories
- Some categories missing on wp-admin/edit-tags.php?taxonomy=category
- List just subcategory and products of active category page in Woocommerce
- Eliminate word from $term->name
- Style a category from category list
- How to schedule categories?
- Copy post taxonomy?
- Displaying a custom field in Category Archives
- Custom Fields Value As Taxonomy
- How to get posts using category slug in ClassiPress?
- Combining these queries? (Same taxonomy term + same category as post)
- Adding tinymce to Custom Field boxes on Category edit page
- get_the_category – display only a single category for a post (not all categories)
- display category with background color
- Disable Category Taxonomy
- Sort categories by custom field in WordPress admin
- How to use the Term Object from a custom select field in a query
- How to set acf color field as background color to product category
- How to target all woocommerce categories that don’t have any subcategories in them?
- Filtering posts in category by tag URL
- Modifying category order
- How can I add different custom fields for each category in the same post?
- get taxonomy list in a page in the wordpress
- Number of categories slowing down the site
- Image Upload Custom Form Field for Category and Custom Taxonomy
- Ajax Category add doesn’t update the list table custom column
- How get all media from a posts category by db?
- How can I add HTML classes for current taxonomy/term hierarchy into my pages to simplify styles?
- Grouping parent categories into sections
- $args Orderby The number
- get_adjacent_post_link excluded_terms ignored
- ACF plugin categories bug in WordPress 3.9
- Taxonomy for custom post type not found
- Category base 404 – fix
- Formating content in category.php
- Assign a category by user and customize the edit-tags.php?taxonomy=category page
- Woocommerce custom taxonomy order
- Hook action when create new category [duplicate]
- Images as Categories
- Quick Edit on taxonomy names results in error