用WordPress高级自定义字段覆盖摘录
问题描述:
我是新来的WordPress,我们有一个表格,人们可以填写提交到我们的网站上的帖子。用WordPress高级自定义字段覆盖摘录
我们使用高级自定义字段插件来填写我们需要的所有必要信息。我们的领域是story_description。
我想使story_description使用所有摘录过滤器(长度等)并将其保存在wp_posts表的post_excerpt下。
我会如何去保存那张表中的自定义长度和定义的摘录中的其他特定内容?我是所有过滤器和操作的新手。
有没有办法只是覆盖是和待遇就像一个正常的摘要时,保存该职位?
我很感激任何回应。
答
你首先需要添加以下允许循环外摘录代(这去你的主题的functions.php):
function rw_trim_excerpt($text='')
{
$text = strip_shortcodes($text);
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
return wp_trim_words($text, $excerpt_length, $excerpt_more);
}
add_filter('wp_trim_excerpt', 'rw_trim_excerpt');
此功能来自jlengstorf answer。当您插入您的文章做以下
然后:
wp_insert_post(array(
// ... other stuffs ...
post_excerpt => apply_filters('get_the_excerpt', $story_description)
));
这将与所有的摘录WP功能筛选$story_description
字符串。