Category images are not displaying in WordPress

Question

I have categories list with there respective images. I am able to get the category name and description but I am not getting the category image. I tried the below code.

<ul>
  <?php
    $categories = get_categories( array(
        'taxonomy'   => 'category',
        'orderby'    => 'name',
        'parent'     => 0,
        'hide_empty' => 0, 
    ) );
    
        foreach ( $categories as $category ) 
        {
        $cat_ID        = $category->term_id;
        $category_name = $category->name;
        $category_desc = $category->description;
        //$category_img = $category->category_images;
        $category_images = get_option('category_images');?>

       <li>
       <?php
       echo $category_name;
       echo $category_desc;
       echo $category_images; //display the path of image for temporary
          ?>         
      </li>
      <?php } ?>
    </ul>

I am getting the var_dump($category_images) output

array(9) {
  [17]=>
  string(0) ""
  [18]=>
  string(63) "http://test.com/wp-content/uploads/2020/08/reghwij.png"
  [19]=>
  string(63) "http://test.com/wp-content/uploads/2020/08/hgeioiq.jpg"
  [21]=>
  string(88) "http://test.com/wp-content/uploads/2020/07/dan-freeman-m4-wkz4GV04-unsplash.png"
  [22]=>
  string(68) "http://test.com/wp-content/uploads/2020/07/green-breaks.jpg"

}

var_dump($category) Output

enter image description here

0
, , , Naren Verma 4 months 0 Answers 42 views 0

Leave an answer