Answers:
您可以通过多种方式进行操作。以下是最好的两种方法。
$post_id = 5// example post id
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo do_shortcode( $content );//executing shortcodes
另一种方法
$content = get_post_field('post_content', $post_id);
echo do_shortcode( $content );//executing shortcodes
在Pieter Goosen提出意见之后apply_filters
。
apply_filters
如果您希望内容被其他插件过滤,则可以使用。因此,这消除了使用的需要do_shortcode
例
$post_id = 5// example post id
$post_content = get_post($post_id);
$content = $post_content->post_content;
echo apply_filters('the_content',$content);
//no need to use do_shortcode, but content might be filtered by other plugins.
如果您不想允许其他插件过滤此内容并需要简码功能,请使用do_shortcode
。
如果您也不想使用简码,请使用post_content
。
do_shortcode
raw content
职位。帖子中嵌入的任何短代码都不会被处理。因此,我们将通过do_shortcode
apply_filters( 'the_content', $content );
,将所有应用于the_content()
like wpautop
和shortcode处理程序的过滤器应用于$content
。;-)。请注意复数filters
apply_filters
而不是do_shortcode
有意义。但是使用apply_filter
纯粹是基于他们的环境决定。让我也更新我的答案。非常感谢您对社区@PieterGoosen的关心
$id = 23; // add the ID of the page where the zero is
$p = get_page($id);
$t = $p->post_title;
echo '<h3>'.apply_filters('post_title', $t).'</h3>'; // the title is here wrapped with h3
echo apply_filters('the_content', $p->post_content);
通过使用get_page('ID')
。
$page_id = 123; //Page ID
$page_data = get_page($page_id);
$title = $page_data->post_title;
$content = $page_data->post_content;
get_page()
已贬值
get_page()
。很久以前就弃用了它。另外,关于此问题,网站上有无限数量的资源,即使Google对此也有大量信息