0

I just changed a crucial aspect of my theme, and posts tagged with a particular taxonomy called position are now handled by a custom meta field called cmb_position_name.

  • Posts that have the taxonomy position with the term event_highlights should now have a cmb_position_event_highlights meta value of on.

  • Posts that have the taxonomy position with the term featured_news should now have a cmb_position_featured_news meta value of on.

  • Posts that have the taxonomy position with the term slider should now have a cmb_position_slider meta value of on.

I need to make a script that migrates existing posts, adding these meta values accordingly.

What is a good place to put this script so that it is executed once, and ensures all the posts are migrated properly?

1
  • You can create a plugin, run it once and delete it or you can create an stand alone script placed wherever you want that load wordpress and you execute once. I think there is not better option, personally I prefer the second one in most cases.
    – cybmeta
    Commented May 10, 2014 at 22:27

1 Answer 1

0

Your options are:

  1. Paste the code into a plugin
  2. Paste the code into a mu-plugin file
  3. Paste the code into a theme file like functions.php

I manage this kind of thing with a plugin that builds a simple interface-- basically an "execute" button. I alter the code that executes as needed. That seems to give me the most control. The code only executes when I navigate to the right screen and run it intentionally.

Pasting into functions.php, or similar, and then quickly deleting the code is not a reliable way to run code once. That code will run as many times as your site has visitors before you can delete it again.

You could save an option to the database on first run to prevent a second fire, but that seems like overkill for this kind of "maintenance" code.

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.