I have editted the MMT Designer function. This works better for me:
if ( ! function_exists( 'get_primary_taxonomy_id' ) ) {
function get_primary_taxonomy_id( $post_id, $taxonomy ) {
$prm_term = '';
if (class_exists('WPSEO_Primary_Term')) {
$wpseo_primary_term = new WPSEO_Primary_Term( $taxonomy, $post_id );
$prm_term = $wpseo_primary_term->get_primary_term();
}
if ( !is_object($wpseo_primary_term) || empty( $prm_term ) ) {
$term = wp_get_post_terms( $post_id, $taxonomy );
if (isset( $term ) && !empty( $term ) ) {
return $term[0]->term_id;
} else {
return '';
}
}
return $wpseo_primary_term->get_primary_term();
}
}
Related Posts:
- How to display only 3 main categories, separated by commas, since they are marked in the post?
- Elegant way to add parent categories?
- How can I reduce the number of database query calls for this custom homepage?
- How to convert regular categories to custom taxonomy?
- What could be causing my wp_query pagination to break?
- Using same slug name for a page and category
- List Categories of the Parent Category of the Current Category
- Return array of categories to php function
- Link each category to last post
- Auto add pages to category menu
- Removing the number in a category slug
- Get term by slug in Gutenberg
- Custom Stylings for category pages
- If newest post of category is newest post in general, skip first post of category
- Show only first children level of current category?
- Taxonomies for WordPress Media Library [duplicate]
- Problem displaying one post from each category
- How do I automatically put categories and their descriptions on a WP Page?
- Taxonomy filter all children
- Bulk category update is not updating
- WC 3.x Get categories from variable product of the cart
- RSS/XML of all Categories and/or Tags
- URL path for wordpress categories
- get_posts and multiple categories
- How do I get rid of “category” from my URL structure?
- Checkboxes in the category list?
- Automatically exclude categories from metabox based on title
- How to display post categories within the Latest Posts block?
- Have different permalinks based on category
- How do I output all category with custom field?
- Add /category/ to an author archive page
- Remove subcategory and category with some rules from permalink
- How can I edit the ‘Most Used’ tab in the categories meta-box to show another custom taxonomy?
- How to remove specific categories from posts?
- Does “show_option_all” in wp_list_categories do anything?
- redirecting from a general category page to another specific one
- how to get full category path including parent and subcategories
- WordPress get from single.php back to the right category page
- Categories are not listing their respective products
- Two columns in homepage each with one category
- Pagination on category.php and tag.php not working
- How to do paging in the loop?
- query_posts not reading correct categories
- WordPress link to post links to category (loop)
- How do I attach a page to a category similar to how we attach media to a post?
- Display all product tags associated with a specific product category
- How replace individual elements in the RSS feed with a single string
- how to nest specific category thumbnails inside different containers
- Eliminate word from $term->name
- Is there any way to check which wordpress categories was created by which user?
- Adding a block with query in homepage
- what file I need to create to work date archive links?
- multiple values in an array for category__and does not work with WP_Query
- Category view with contents of [gallery]s shown
- Assigning certain pages or posts to use the template of the parent page or category
- How can I include custom category and tag base in template files?
- How to get posts using category slug in ClassiPress?
- query_post problem
- Assign author to category and not only posts
- Add properties to term object
- Display all Categories
- custom wp_list_categories in single.php
- How to target all woocommerce categories that don’t have any subcategories in them?
- Is this process OK to replace URL structure?
- echo $category[0]-> cat_name; shows only one category name
- How can i echo next and previous custom category from a Taxonomy
- Change post category within pre_get_posts
- No hierarchy in wp_list_categories with child of and depth
- How to check a category checkbox using JavaScript
- Ajax Category add doesn’t update the list table custom column
- Need help to structure our a complex hierarchy
- global categories – Share specific categories in wordpress multisite
- how to get postmeta info based on multiple categories?
- create post with main category and other categories from admin panel
- How Can Hide Define Category in Post Contents?
- How to auto update post title and slug with category name when post status is updated
- get_posts – require all categories
- 404 error when i try to search by category or by tag
- Choosing different templates for categories
- Problem with wp_list_categories
- List Terms by category
- Add advertising box to a specific category page
- How do you add Author and date Published on Category Pages?
- hierarchical taxonomy in permalinks? using same slug
- WordPress Numeric Pagination with Query String [duplicate]
- Changing Permalinks for Category Pages Only
- Twenty Eleven Theme [duplicate]
- display certain category on custom template page
- Get post by Category in custom template
- Ajax call activate after submit in edit-tags.php page
- List products from current category
- Assign a category by user and customize the edit-tags.php?taxonomy=category page
- comments_number fails to print
- Sorting Woocommerce products by category and attributes
- How to show posts of a specific category
- How to show child category name & post from it’s parent [closed]
- Open everything in new tab
- hide_empty property not working when using get_terms
- Category Redirection Problem
- Hierarchical outline of posts