Tuesday, February 19, 2019

How to get all subcategory using parent category id in Wordpress

$args = array('parent' => 17);

$categories = get_categories( $args );

foreach($categories as $category)
{
    echo '<p>Category:
    <a href="' . get_category_link( $category->term_id ) . '"
    title="' . sprintf( __( "View all posts in %s" ),
    $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    echo '<p> Description:'. $category->description . '</p>';
    echo '<p> Post Count: '. $category->count . '</p>'; 
}

No comments:

Post a Comment