te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>Wordpress get_the_content not returning HTML contents; ie gutenberg content - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Wordpress get_the_content not returning HTML contents; ie gutenberg content - Stack Overflow

programmeradmin1浏览0评论

I'm trying to get the content of a Wordpress post as plain text. Looking in the database is see this in column post_content

<!-- wp:acf/banner-slim {"name":"acf/banner-slim","data":{"subhead":"","_subhead":"field_674cafb053c24"},"mode":"auto"} /-->
foobar 
<!-- wp:acf/block-intro-child {"name":"acf/block-intro-child","data":{"intro":"Effective B2B digital marketing is about skilled performance. The stats don’t lie. If a campaign fails, you can’t justify the cost by saying it was ‘good for the brand’.\r\n\r\nSuccessful performance requires a number of factors to come together, each being deep specialisms in their own right. ","_intro":"field_67b3632a5dc58","breakout":"At our B2B digital marketing agency in Bath we work in local, national and international markets. We are strategically led and constantly thinking of ways to make your marketing more effective. ","_breakout":"field_67b363775dc59"},"mode":"auto"} /-->

but when I use various Wordpress functions to try to get the content without filters – get_the_content(), $post->$post_content all I get is foobar (I inserted this into the database column myself). The rest, enclosed in HTML comments is stripped out.

How do I load this content into a variable without any stripping?

At the moment any attempt to load the WP_Object into a variable results in this;

WP_Post Object ( 
[ID] => 8349 
[post_author] => 1 
[post_date] => 2024-11-29 08:19:01 
[post_date_gmt] => 2024-11-29 08:19:01 
[post_content] => foobar

[post_title] => Strategic B2B Marketing 
[...]

I'm trying to get the content of a Wordpress post as plain text. Looking in the database is see this in column post_content

<!-- wp:acf/banner-slim {"name":"acf/banner-slim","data":{"subhead":"","_subhead":"field_674cafb053c24"},"mode":"auto"} /-->
foobar 
<!-- wp:acf/block-intro-child {"name":"acf/block-intro-child","data":{"intro":"Effective B2B digital marketing is about skilled performance. The stats don’t lie. If a campaign fails, you can’t justify the cost by saying it was ‘good for the brand’.\r\n\r\nSuccessful performance requires a number of factors to come together, each being deep specialisms in their own right. ","_intro":"field_67b3632a5dc58","breakout":"At our B2B digital marketing agency in Bath we work in local, national and international markets. We are strategically led and constantly thinking of ways to make your marketing more effective. ","_breakout":"field_67b363775dc59"},"mode":"auto"} /-->

but when I use various Wordpress functions to try to get the content without filters – get_the_content(), $post->$post_content all I get is foobar (I inserted this into the database column myself). The rest, enclosed in HTML comments is stripped out.

How do I load this content into a variable without any stripping?

At the moment any attempt to load the WP_Object into a variable results in this;

WP_Post Object ( 
[ID] => 8349 
[post_author] => 1 
[post_date] => 2024-11-29 08:19:01 
[post_date_gmt] => 2024-11-29 08:19:01 
[post_content] => foobar

[post_title] => Strategic B2B Marketing 
[...]
Share Improve this question asked Feb 17 at 17:26 Chris PinkChris Pink 2,0272 gold badges20 silver badges32 bronze badges 2
  • Even $post_id = get_the_id(); $sql = "SELECT post_content FROM wp_posts WHERE ID = $post_id"; global $wpdb; $result = $wpdb->get_results($sql); print_r($result); Strips out the html comment. How does this work? – Chris Pink Commented Feb 17 at 17:38
  • Use parse_blocks($post->post_content) - that should get you everything. Also, since that's rendering block code I think wp adds it on the server side, it's not in the post_content property of the object. – disinfor Commented Feb 17 at 21:53
Add a comment  | 

2 Answers 2

Reset to default 3

whether you use get_the_content() or get_post_field() doesn't change the problem, if you want to retrieve the HTML comments used by WordPress, you need to use the htmlentities() function like this:

$content = get_the_content(null, false, $post_id);
echo htmlentities($content);

Or

$content = get_post_field('post_content', $post_id);
echo htmlentities($content);

If you want the raw HTML you can use

$content = get_post_field('post_content', $post_id);
发布评论

评论列表(0)

  1. 暂无评论