0

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>

1 Answer 1

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.

1
  • Thank you so much,its working
    – Rahat
    Nov 28, 2019 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.