admin管理员组

文章数量:1201415

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 2 years ago.

Improve this question

Not having access to the functions file, I can't add the function to add the featured image to the API so I need to use wp-json/wp/v2/posts?_embed.

With javascript I believe it is ._embedded['wp:featuredmedia']['0'].source_url so I tried with php after using wp_remote_get, $post->_embedded['wp:featuredmedia'][0]->source_url but the error I am getting is :

Cannot use object of type stdClass as array

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 2 years ago.

Improve this question

Not having access to the functions file, I can't add the function to add the featured image to the API so I need to use wp-json/wp/v2/posts?_embed.

With javascript I believe it is ._embedded['wp:featuredmedia']['0'].source_url so I tried with php after using wp_remote_get, $post->_embedded['wp:featuredmedia'][0]->source_url but the error I am getting is :

Cannot use object of type stdClass as array

Share Improve this question asked Jun 2, 2022 at 13:03 user8463989user8463989 5931 gold badge8 silver badges24 bronze badges 4
  • 1 Your question is a PHP question that's better suited at Stack Overflow. And I just wanted to say FYI, you're getting that error because $post->_embedded is an object which is an instance of the generic "empty" class in PHP, namely stdClass. So you should've instead used $post->_embedded->{'wp:featuredmedia'}. – Sally CJ Commented Jun 2, 2022 at 13:52
  • @SallyCJ good point, I just thought to ask here in the hope that someone else had this issue. Doing as you suggested was spot on and worked perfectly. You should add it as an answer :) – user8463989 Commented Jun 3, 2022 at 5:06
  • So I guessed it correctly that you used something like $post = json_decode( 'JSON string' ) ?

    本文标签: postsGetting featured image with PHP and not javascript from wordpress api embed