gpt4 book ai didi

php - 仅显示父自定义分类名称?

转载 作者:行者123 更新时间:2023-12-04 00:09:40 24 4
gpt4 key购买 nike

我想只显示父类别名称而不是子类别名称没有在任何产品或帖子中使用,我只需要列出父自定义类别。

我尝试了 get_termswp_list_categories 功能,但它的显示 child 也

这是我的代码。

<?php 
require_once('connection.php');
$taxonomy = 'product_cat';
$orderby = 'parent';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 0; // 1 for yes, 0 for no
$title = '';
$empty = 0;

$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'childless' => false,
'child_of' => 0,
'title_li' => $title,
'hide_empty' => $empty,
'hierarchical'=>1
//'hierarchical=0&depth=1'
);

$rrr=wp_list_categories( $args );
print_r($rrr);
?>

它也显示 child ,但我只需要父类别名称。

i used Product_cat is a woocommerce category and when i used it with get_terms it's given null array.

i used like this way also but product_cat is not working with get_terms

<?php
$parent_cat_arg = array('hide_empty' => false, 'parent' => 0 );
$parent_cat = get_terms('product_cat',$parent_cat_arg);

foreach ($parent_cat as $catVal) {
/*some code*/
}
?>

请参阅附件图片,我已经解释了我需要什么。

enter image description here

最佳答案

试试这个设置 parent0

 $taxonomy     = 'product_cat';
$orderby = 'parent';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 0; // 1 for yes, 0 for no
$title = '';
$empty = 0;

$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'childless' => 0,
'child_of' => 0,
'title_li' => $title,
'hide_empty' => $empty,
'parent'=>0,

);

$rrr=wp_list_categories( $args );
print_r($rrr);

关于php - 仅显示父自定义分类名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37961430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com