Get Children IDs of a Parent Taxonomy Category in WordPress
In WordPress, you can get the children IDs of a parent taxonomy category using the 'get_term_children()' function. Here's an example of how you can achieve this:
$parent_category_id = 10; // replace with the actual ID of the parent category
$child_ids = get_term_children( $parent_category_id, 'category' ); // replace 'category' with your taxonomy name
// Loop through the child IDs
foreach ( $child_ids as $child_id ) {
echo $child_id . '<br>';
}
In the code above, we first set the '$parent_category_id' variable to the ID of the parent category whose children we want to retrieve.
Then, we use the 'get_term_children()' function passing the '$parent_category_id' and the taxonomy name as parameters. This function returns an array of IDs for the children of the specified parent category.
Finally, we loop through the child IDs using a 'foreach' loop and echo each ID.
Note: Make sure to replace 'category' with the actual name of your taxonomy.
原文地址: https://www.cveoy.top/t/topic/qjha 著作权归作者所有。请勿转载和采集!