Wordpress 如果url包含变量,则无法获取当前术语id
我试图在woocommerce类别页面上获取当前术语id。 仅当url不包含以下变量时,我才能获取术语id:Wordpress 如果url包含变量,则无法获取当前术语id,wordpress,woocommerce,Wordpress,Woocommerce,我试图在woocommerce类别页面上获取当前术语id。 仅当url不包含以下变量时,我才能获取术语id: ?swoof=1&product_cat=femmes,bijoux&page=1 它对我有用 我需要获得女性分类ID 但不适用于http://www.example.com/categorie-produit/femmes/?swoof=1&product_cat=femmes,bijoux&page=1 我使用以下代码获取术语id: get_queried_obje
?swoof=1&product_cat=femmes,bijoux&page=1
它对我有用
我需要获得女性分类ID
但不适用于http://www.example.com/categorie-produit/femmes/?swoof=1&product_cat=femmes,bijoux&page=1
我使用以下代码获取术语id:
get_queried_object()->term_id
我需要获取femmes类别ID。请尝试以下代码
$categoryIds = get_query_var('product_cat');
$cats = explode(',',$categoryIds);
$cat_obj = get_term_by('slug', $cats[0] , 'product_cat');
$categoryID = $cat_obj->term_id;
在$categoryId中,您将获得从家长到孩子的所有类别。非常全面的答案!