Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从permalink Wordpress获取多个类别名称_Wordpress_Categories_Permalinks - Fatal编程技术网

从permalink Wordpress获取多个类别名称

从permalink Wordpress获取多个类别名称,wordpress,categories,permalinks,Wordpress,Categories,Permalinks,我正在尝试获取permalink中可用的类别名称。e、 我有下面的永久链接结构 abc.com/product category/category-1/category-2/ 其中,as类别1和类别2都是类别。当我尝试$wp\u query->get\u queryed\u object()时,它只会返回与类别2相关的信息。如何使用现有的wordpress函数获取类别1的详细信息 谢谢您可以使用get\u term功能获取category-2的父项 $child\u term=get\u que

我正在尝试获取permalink中可用的类别名称。e、 我有下面的永久链接结构

abc.com/product category/category-1/category-2/

其中,as类别1类别2都是类别。当我尝试
$wp\u query->get\u queryed\u object()
时,它只会返回与类别2相关的信息。如何使用现有的wordpress函数获取类别1的详细信息


谢谢

您可以使用
get\u term
功能获取
category-2
的父项

$child\u term=get\u queryed\u object();
$parent_term=get_term($child_term->parent,'product_cat');//如果您使用的是Woocommerce,则分类法称为“product_cat”
这两个变量都是
WP\u Term
对象

从那里,您可以访问姓名、id和您需要的任何其他信息

修订版

如果您想要创建自定义类别页面(即不是Woocommerce/WordPress页面),那么我建议在页面编辑器中添加一个
元框

有一个包含产品类别的选择框


然后在页面模板中,使用
术语ID
作为
WP_查询的一部分,从这两个产品类别中提取产品。

您可以使用
获取术语
功能获取
类别-2
的父级

$child\u term=get\u queryed\u object();
$parent_term=get_term($child_term->parent,'product_cat');//如果您使用的是Woocommerce,则分类法称为“product_cat”
这两个变量都是
WP\u Term
对象

从那里,您可以访问姓名、id和您需要的任何其他信息

修订版

如果您想要创建自定义类别页面(即不是Woocommerce/WordPress页面),那么我建议在页面编辑器中添加一个
元框

有一个包含产品类别的选择框


然后在页面模板中,使用
术语ID
作为
WP\u查询的一部分,从这两个产品类别中提取产品。

由于前面的类别是当前使用的父类,因此可以使用get\u术语获取产品 $child_category=$wp_query->get_queryed_object();
$parent_category=get_term($child_category->parent,'product category')

由于前面的类别是当前使用的父类,因此可以使用get\u术语获取它 $child_category=$wp_query->get_queryed_object();
$parent_category=get_term($child_category->parent,'product category')

get\u category
get\u terms
的包装,其中
taxonomy
已设置为
categories
,因此我相信您可能只会用它来提取常规的post-type术语,所以我认为产品不在该分类中。啊!对,我没有看到产品类别部分,get_terms当然更通用。
get_category
get_terms
的包装,其中
taxonomy
已经设置为
categories
,所以我相信您可能只会用它来提取常规的post类型术语,所以我想象产品不在该分类中。啊!对,我没有看到产品类别部分,get_术语当然更通用。类别1和类别2都处于同一级别。它不是父子关系。你是如何设置URL的?它会建议家长/孩子基本上就像我用那个url进行过滤一样。它带来了属于类别1和类别2的所有产品。我已经用一个像样的解决方案修改了我的答案。因此,wordpress没有核心功能,我可以使用permalink获得两个类别名称?类别1和类别2都处于同一级别。它不是父子关系。你是如何设置URL的?它会建议家长/孩子基本上就像我用那个url进行过滤一样。它带来了属于1类和2类的所有产品。我已经用一个不错的解决方案修改了我的答案。所以wordpress没有核心功能,我可以使用permalink获得这两个类别的名称?