Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按ID获取_内容并保留<;p>-WordPress中的标签_Php_Wordpress - Fatal编程技术网

Php 按ID获取_内容并保留<;p>-WordPress中的标签

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

我想通过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_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(']]>', ']]&gt;', $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)。“”;