我想通过ID获取自定义帖子类型的内容,并以简码形式返回。
我发现有多种方法可以做到这一点。但是所有这些<p>
都从内容中删除了-tags。
这是我尝试过的:
// Get the ID from a meta field
$post_id = $id;
// Method 1
$banner_content = get_post($post_id);
$content = $banner_content->post_content;
// Method 2
$content = apply_filters('the_content', get_post_field('post_content', $post_id));
// Method 3
$content_post = get_post($post_id);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
// Method 4
$content = get_post_field('post_content', $post_id);
// Output in a shortcode
return '<div>'.$content.'</div>';
有没有办法保留<p>
-tag?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句