admin管理员组

文章数量:1406063

By this code ,it shows all the category.but i want to show specific some category(like-Officer,Training) Thanks in Advance

    <?php 
        // change category to your custom page slug
        $categories = get_categories(); 
        foreach ($categories as $category) {
            $option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">';
            $option .= $category->cat_name;
            $option .= ' ('.$category->category_count.')';
            $option .= '</option>';
        }
        echo $option;
    ?>
</select>

By this code ,it shows all the category.but i want to show specific some category(like-Officer,Training) Thanks in Advance

    <?php 
        // change category to your custom page slug
        $categories = get_categories(); 
        foreach ($categories as $category) {
            $option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">';
            $option .= $category->cat_name;
            $option .= ' ('.$category->category_count.')';
            $option .= '</option>';
        }
        echo $option;
    ?>
</select>
Share Improve this question asked Nov 28, 2019 at 9:58 RahatRahat 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
<?php 
    // change category to your custom page slug
    $categories = get_categories( array( 'include' => array(1, 2, 3) ) ); 
    foreach ($categories as $category) {
        $option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">';
        $option .= $category->cat_name;
        $option .= ' ('.$category->category_count.')';
        $option .= '</option>';
    }
    echo $option;
?>

array(1, 2, 3) is category ids.

本文标签: phpHow can i show specific Category List