Php 按ID获取_内容并保留<;p>-WordPress中的标签
我想通过ID获取自定义帖子类型的内容,并在短代码中返回它 我找到了多种方法。但是它们都从内容中删除了Php 按ID获取_内容并保留<;p>-WordPress中的标签,php,wordpress,Php,Wordpress,我想通过ID获取自定义帖子类型的内容,并在短代码中返回它 我找到了多种方法。但是它们都从内容中删除了-标记 以下是我尝试过的: // 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_fil
-标记
以下是我尝试过的:
// 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>';
//从元字段获取ID
$post_id=$id;
//方法1
$banner\u content=get\u post($post\u id);
$content=$banner\u content->post\u content;
//方法2
$content=apply_filters('the_content',get_post_字段('post_content',$post_id));
//方法3
$content\u post=get\u post($post\u id);
$content=$content\u post->post\u content;
$content=apply_过滤器('the_content',$content);
$content=str_replace(']]>',']]',$content);
//方法4
$content=get\u post\u字段($post\u content',$post\u id);
//短代码中的输出
返回“.$content.”;
有没有办法保留
-tag?我在这里找到了答案:
以我为例,这是有效的:
return '<div>'.wpautop($content).'</div>';
返回“”。wpautop($content)。“”;
我在这里找到了答案:
以我为例,这是有效的:
return '<div>'.wpautop($content).'</div>';
返回“”。wpautop($content)。“”;