admin管理员组文章数量:1122832
I have the following code in my functions.php file that I'm using to create a custom meta_key called 'spec_wp' (which is based on the value of an ACF repeater):
add_filter('acf/save_post', 'convert_spec_to_standard_wp_meta', 20);
function convert_spec_to_standard_wp_meta($post_id) {
$meta_key = 'spec_wp';
delete_post_meta($post_id, $meta_key);
$saved_values = array();
if (have_rows('specs', $post_id)) {
while (have_rows('specs', $post_id)) {
the_row();
$specval = get_sub_field('spec_value');
if (isset($saved_values[$specval])) {
continue;
}
add_post_meta($post_id, $meta_key, $specval, false);
$saved_values[$specval] = $specval;
}
}
}
The code works as intended, but spec_wp is only created for a post when that post is updated from its edit screen.
Does anyone know of a way to bulk-update posts so that I don't have to go through and update them one by one? I have 1,700 posts that need this meta_key, so updating them all manually isn't really an option.
I've tried using the 'bulk actions' > 'edit' > 'update' feature in on the 'all posts' page but it doesn't seem to work.
I've also tried changing the action to 'acf/init' and just 'init', but that didn't work either.
I have the following code in my functions.php file that I'm using to create a custom meta_key called 'spec_wp' (which is based on the value of an ACF repeater):
add_filter('acf/save_post', 'convert_spec_to_standard_wp_meta', 20);
function convert_spec_to_standard_wp_meta($post_id) {
$meta_key = 'spec_wp';
delete_post_meta($post_id, $meta_key);
$saved_values = array();
if (have_rows('specs', $post_id)) {
while (have_rows('specs', $post_id)) {
the_row();
$specval = get_sub_field('spec_value');
if (isset($saved_values[$specval])) {
continue;
}
add_post_meta($post_id, $meta_key, $specval, false);
$saved_values[$specval] = $specval;
}
}
}
The code works as intended, but spec_wp is only created for a post when that post is updated from its edit screen.
Does anyone know of a way to bulk-update posts so that I don't have to go through and update them one by one? I have 1,700 posts that need this meta_key, so updating them all manually isn't really an option.
I've tried using the 'bulk actions' > 'edit' > 'update' feature in on the 'all posts' page but it doesn't seem to work.
I've also tried changing the action to 'acf/init' and just 'init', but that didn't work either.
Share Improve this question asked Aug 17, 2018 at 19:55 LCWLCW 335 bronze badges1 Answer
Reset to default 0Yes, there's an efficient way to bulk-update your posts without manually editing each one.
You can use a premium plugin like Bulk Task Editor for WordPress, which is designed to handle large-scale updates seamlessly.
Here’s how it works:
- Advanced Search & Filter: Easily locate the posts you need to update using advanced search and filter options.
- Bulk Actions: Apply bulk actions to update the
meta_key
across all 1,700 posts in one go. - Execution Methods: Tasks can be processed via JavaScript in the frontend or scheduled to run in the background using CRON jobs, ensuring your server doesn't get overloaded.
Steps to Use Bulk Task Editor:
Install and Activate the Plugin:
- Download and install the plugin from here.
Configure Your Task:
- Use the plugin's interface to set up your bulk task.
- Specify the posts you want to update using the search and filter options.
Schedule and Execute:
- Choose whether to execute the task immediately via JavaScript or schedule it as a CRON job to run in the background.
This should save you a lot of time and effort compared to manually updating each post.
If you need further customization or more complex tasks, the plugin also supports adding custom functions.
本文标签: BulkUpdate Custom Posts
版权声明:本文标题:Bulk-Update Custom Posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298862a1930318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论