add_action('publish_post', 'custom_post_webhook',10 , 2);
function custom_post_webhook($post_id, $post){
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id));
$url = 'https://example.com/postmydata';
$args = array(
'blocking'=>false,
'sslverify'=> false,
'body' => json_encode(array($post,array('post_thumbnail' => $image)
)),
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'method' => 'POST',
'data_format' => 'body',
);
wp_remote_post($url, $args);
}
问题是我永远无法获得 $image 值,无论使用什么函数来获取它,它总是返回 false 或 null;如果我像这样使用上一个帖子 ID:
wp_get_attachment_image_src(get_post_thumbnail_id(332))
它工作得很好,但如果我使用当前的帖子值,它总是给我 false 或 null,具体取决于我用来检索 url 的函数。有人可以帮我完成这项工作吗?