2

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.

1 Answer 1

0

Yes, 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:

  1. Advanced Search & Filter: Easily locate the posts you need to update using advanced search and filter options.
  2. Bulk Actions: Apply bulk actions to update the meta_key across all 1,700 posts in one go.
  3. 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:

  1. Install and Activate the Plugin:

    • Download and install the plugin from here.
  2. 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.
  3. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.