我有一个有超过10.000条帖子的博客。我需要的是为我的所有帖子生成一个字幕,从每个帖子的摘要字段的内容中提取该文本。作为图像的例子,我包括在这篇文章。
摘录字幕我想请求帮助找到理想的functions.php代码。
my_subtitle($article)
get_the_excerpt()
或者,如果有人可以用phpmyadmin SQL引导我批量更新我现有文章中的这些字段。
提前谢谢。
发布于 2020-03-26 00:50:09
您可以使用get_posts和一个foreach循环“强制执行”:
$posts = get_posts([
'post_type' => 'post',
'posts_per_page' => -1, // will grab all
'post_status' => ['publish', 'draft']
]);
foreach ($posts as $post) {
// get post id from $post object
$post_id = $post->ID;
// get the excerpt
$excerpt = get_the_excerpt($post_id);
// there is no "sub title" function in WordPress so we can save it as postmeta
update_post_meta($post_id, 'my_sub_title', $excerpt);
}https://stackoverflow.com/questions/60851350
复制相似问题