我想通過 ID 獲取自定義帖子類型的內(nèi)容,并在短代碼中返回它。我找到了多種方法來做到這一點(diǎn)。但是他們<p>都從內(nèi)容中刪除了-tags。這是我嘗試過的:// 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 shortcodereturn '<div>'.$content.'</div>';有沒有辦法保留<p>-tag?
1 回答

GCT1015
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
對于我的示例,這有效:
return '<div>'.wpautop($content).'</div>';
- 1 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)
0/150
提交
取消