customization - Not display an image of category of custom post

$cats = array('taxonomy'=>'types');$categories = get_categories($cats);foreach($categories as $c

$cats = array('taxonomy'=>'types');

$categories = get_categories($cats);
foreach($categories as $category) { 
    echo '<p>Category:'. $category->name.' </p> <br>';
    echo '<p> Description:'. $category->description . '</p> <br>';
    $term_id = $category->term_id;
    echo $term_id;
    $meta_image = wp_get_attachment_image($category->$term_id); 
    echo $meta_image; 
    ?>
       <img src="<?=$meta_image?>" alt="image">
    <?php
}
$cats = array('taxonomy'=>'types');

$categories = get_categories($cats);
foreach($categories as $category) { 
    echo '<p>Category:'. $category->name.' </p> <br>';
    echo '<p> Description:'. $category->description . '</p> <br>';
    $term_id = $category->term_id;
    echo $term_id;
    $meta_image = wp_get_attachment_image($category->$term_id); 
    echo $meta_image; 
    ?>
       <img src="<?=$meta_image?>" alt="image">
    <?php
}
Share Improve this question edited Aug 27, 2019 at 6:36 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Aug 27, 2019 at 4:50 Naeem DhattiwalaNaeem Dhattiwala 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

First of all $category->$term_id is wrong use $category->term_id

I don't think $category->$term_id will give you the desired result

For this you must have create some meta for the image in the backend.

term_image_id = get_term_meta( $category->term_id, 'your-term-id', true );

Here the term id is $category->term_id and the term value is your-term-id

Can you please check if that works or not?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745209358a4616745.html

相关推荐

  • customization - Not display an image of category of custom post

    $cats = array('taxonomy'=>'types');$categories = get_categories($cats);foreach($categories as $c

    12小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信