我正在使用 get_post(post_id)
获取 post_title
和 post_content
。我想将它们连接起来,post_title
将成为新字符串中的第一段。
例如。
$post_title = 'Hi all, welcome here'
$post_content = 'lorem ipsum bla bla la
new paragraph bla bla bla
new paragrapg lorem ipsum'
我期望这样的结果:
Hi all, welcome here
lorem ipsum bla bla la
new paragraph bla bla bla
new paragrapg lorem ipsum
但我不知道如何在 post_title
之后传递新的段落字符。在数据库 View (mysql)中,没有标签只有空格或 Conceal 字符。我在尝试:
$new_string = $post_title.'/r/n'.$post_content
$new_string = '<p>'.$post_title.'</p>'.$post_content
但它不会起作用。
完成此操作后,我想使用 apply_filters('the_content', $new_content)
获得这个新字符串的正确 View ,并使用 facebook SDK 将其发送到 facebook fanpage。
最佳答案
您应该使用 nl2br() 函数在段落中换行。它会将所有\n 转换为新行。
$new_string = nl2br($post_title.$post_content);
关于php - 如何将 post_title 与 post_content 与 html 连接起来 - wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44630774/