我编写了以下函数来获取publish post上的post数据,但我看到post\\u meta不可用,它总是空的。如何在publish\\u post hook上检索帖子的帖子元数据?
归根结底,我想收集数据$article转换为json并使用curl发布。当我使用print_r(json_encode($article))
它实际上执行内容和输出中的html标记。有没有像wp\\u send\\u json那样的简洁方法?
add_action( \'publish_post\', \'newdb\',10,2);
function newdb($post_id, $post){
if($post_id !=null){
$article[\'postID\'] = $post->ID;
$article[\'seo_url\'] = get_permalink($post->ID);
$article[\'title\'] = $post->post_title;
$article[\'status\'] = $post->post_status;
$article[\'body\'] = html_entity_decode(htmlentities(addslashes($post->post_content)));
$article[\'related\'] = array();
$relatedStories = get_post_meta($post->ID, \'realtor_related_stories\', true);
if ($relatedStories != null) {
$rsCount = count($relatedStories) - 1;
while ($rsCount > 0) {
$rStories[\'title\'] = $relatedStories[\'related_stories_attribution_\' . $rsCount][\'headline\'];
$rStories[\'seo_url\'] = $relatedStories[\'related_stories_attribution_\' . $rsCount][\'url\'];
$rStories[\'img_src\'] = wp_get_attachment_url(get_post_thumbnail_id(url_to_postid($rStories[\'seo_url\'])));
array_push($article[\'related\'], $rStories);
$rsCount--;
}
}
$article[\'seo_focus_keyword\'] = get_post_meta($post->ID, \'_yoast_wpseo_focuskw\', true);
$article[\'seo_title\'] = get_post_meta($post->ID, \'_yoast_wpseo_title\', true);
$article[\'seo_metadesc\'] = get_post_meta($post->ID, \'_yoast_wpseo_metadesc\', true);
wp_send_json($article);
//print_r($article) => gives wierd output because of embed tags in post body
}
}