$cat_args = array meta_key = qq_cat_piority orderby = meta_value_num order = ASC hide_empty = false; $qqcpategories = get_terms qqcpat $cat_args ;i want only the first level of this category
To retrieve only the top-level categories and exclude their children, you can use the parent parameter in the get_terms() function. Here's how you can modify the code:
$cat_args = array(
'meta_key' => 'qq_cat_piority',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'hide_empty' => false,
'parent' => 0, // Set the parent parameter to 0 to only get top-level categories
);
$qqcpategories = get_terms('qqcpat', $cat_args);
By setting the parent parameter to 0, you will only retrieve categories that have no parent (i.e., top-level categories)
原文地址: https://www.cveoy.top/t/topic/iBdl 著作权归作者所有。请勿转载和采集!