Programmatically infer categories of a specific Wordpress parent
In the example below, we will display links with the name of the categories of a certain parent rubric
<?php
$categories = get_categories( array(
'taxonomy' => 'category',
'type' => 'post',
'child_of' => '',
'parent' => 2,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => 0,
'pad_counts' => false,
) );
if( $categories ){
foreach( $categories as $cat ){
// Data in object $cat
// $cat->term_id
// $cat->name (Rubric 1)
// $cat->slug (rubrika-1)
// $cat->term_group (0)
// $cat->term_taxonomy_id (4)
// $cat->taxonomy (category)
// $cat->description (Description text)
// $cat->parent (0)
// $cat->count (14)
// $cat->object_id (2743)
// $cat->cat_ID (4)
// $cat->category_count (14)
// $cat->category_description (Description text)
// $cat->cat_name (Rubric 1)
// $cat->category_nicename (rubrika-1)
// $cat->category_parent (0)
echo '<p><a href="'.get_category_link( $cat->term_id ).'">'.$cat->name.'</a></p>';
}
}
?>