I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categories

 $term_id = get_categories();
    if (function_exists('get_wp_term_image'))
    $meta_image = get_wp_term_image($term_id); 
    //It will give category/term image url 
$categories = get_categories();
foreach($categories as $category) {
   <div class="poster"> 
   <a href="<?php echo get_category_link($category->term_id); ?>">
<?php echo '<img src="'.get_wp_term_image($category->term_id).'">' ?>
<div class="orbit_starts">
<h2><?php echo $category->name ?></h2></a>

How would you exclude all subcategories?

Thank you

$args = array(
  'orderby' => 'name',
  'order' => 'ASC',
  'parent' => 0
$categories = get_categories($args);

May this will help you. Refer this link

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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