'Cannot use object of type stdClass as array' using Wordpress

前端 未结 2 1779
再見小時候
再見小時候 2020-12-09 02:59

I am trying to retrieve the slug for a tag inside a wordpress post, now its possible to get all tag info using

$tag = wp_get_post_tags($post->ID);


        
相关标签:
2条回答
  • 2020-12-09 03:19

    Another option should be to explicitly cast $tag[0] into an array:

    $t = (array)$tag[0];
    $t["slug"] = ...
    

    Can't get it to work though

    0 讨论(0)
  • 2020-12-09 03:23

    Note that the array contains objects (instances of stdClass), not other arrays. So the syntax is:

    $tag[0]->slug
    
    0 讨论(0)
提交回复
热议问题