如何通过 WordPress 中的 Yoast seo 插件设置主要类别 [英] How to get primary category set via Yoast seo plugin in WordPress

查看:18
本文介绍了如何通过 WordPress 中的 Yoast seo 插件设置主要类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 Yoast seo 插件并为产品设置了主要类别.但是在前面我无法获得主要类别名称.

I have used a Yoast seo plugin and set primary category for product. But in front I cannot get primary category name.

推荐答案

您可以使用 postmeta 表.

Hi you can get using postmeta table.

   $taxonomy = 'product_cat'; 
   $primary_cat_id=get_post_meta($product->id,'_yoast_wpseo_primary_' . $taxonomy, true);
    if($primary_cat_id){
       $primary_cat = get_term($primary_cat_id, $taxonomy);
       if(isset($primary_cat->name)) 
           echo $primary_cat->name;
    }

这篇关于如何通过 WordPress 中的 Yoast seo 插件设置主要类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆