0

After importing a series of posts (using WP All Import), my (custom) page template is unable to access the post's contents/fields. However, if I open the post in the editor and click "Update" without making any changes, the page template suddenly works perfectly. This makes me assume that some previously non-essential and previously empty database field is inserted.

Although this "bug" is probably due to a nuance in either the Advanced Custom Fields plugin or WP All Import plugin, my testing still suggests that some very minor database state change is happening after clicking the update button (even without making any changes).

Edit: FYI after importing posts, I've tried deactivating all plugins and the issue still persists.

Edit #2: After more testing, it seems that WordPress generates _fields after manual "updates" but not during the import process. Example, importing data into field full_address WordPress will create a _full_address only after a manual update. I'm doing more testing now, but this might be the problem.

6
  • It depends. Any theme or plugin can run some code when the post is updated. It’s impossible to say what might be happening with just this information. Commented Sep 2, 2021 at 10:02
  • do you have a caching plugin installed? Have you looked at the database to see what changed?
    – Tom J Nowell
    Commented Sep 2, 2021 at 10:04
  • @JacobPeattie since I've de-activated every plugin and still have the same results, are you suggesting the issue must be with the theme and nothing WP core related? Commented Sep 2, 2021 at 10:20
  • @TomJNowell Deactivated caching & changed nothing. Due to the nature of the project I didn't set up a full local test environment to make exploring the DB an easy task. After doing some additional digging it seems that the _fields aren't generated automatically. Commented Sep 2, 2021 at 10:22
  • If you’re using ACF, and your export does not include the _ prefixed version of the fields, then it could explain the values of certain fields not appearing correctly. There’s no reason for ACF to assume these fields belong to ACF, and to generate these values on import. ACF only knows to generate these when the field is saved with an ACF function, or if the value is saved with the ACF UI. The issue here is that the fields are not in the data you are importing. If you don’t have that data then this is an issue with WP All Import and ACF. Nothing to do with WordPress. Commented Sep 2, 2021 at 10:26

1 Answer 1

0

To answer my own question, WordPress does not appear to make any changes to the database after a post "Update" that contained no changes. Any changes that happen should be the result of a theme or plugin.

However, the Advanced Custom Fields (ACF) plugin does. Specifically, if ACF fields are set (such as through WP All Import) without also setting the ACF field key reverence, it appears that a click of the "Update" button will add these field key references.

When I attempted to add field key references to my import, I still had issues. Therefore, I found the easiest solution (instead of clicking "Update" on several hundred posts) was to run the following:

function bulk_update_posts() {

    $args = array(  'post_type'=>'post', // Change 'post' if you're using pages or a CPT
                    'posts_per_page'   => -1,
                    'post_status' => array('publish', 'future') // Includes published AND scheduled posts
    );

    $all_posts = get_posts($args);

    foreach($all_posts as $key => $one_post){
        $meta_values = get_post_meta( $one_post->ID);
        foreach($meta_values as $meta_key => $meta_value ){
            update_field($meta_key, $meta_value[0], $one_post->ID);
        }
    }
}
add_action( 'init', 'bulk_update_posts' );
//add_action( 'wp_loaded', 'mass_update_posts' );

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.