• Hi,

    I’m importing posts at large scale via CSV and populating ACF fields from the CSV file. I want to use calculated fields to perform calculations automatically based on the imported field values.

    I’m literally importing thousands of posts so it is impractical for me to manually go into each post individually in order to update the calculated field and get it to display on the front end.

    Is there any way to automatically populate the calculated fields without having to go into each post and update it manually?

    Thanks in advance!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor nick6352683

    (@nick6352683)

    Excellent question, I did not try any of the suggestions that I have, but almost immediately I thought of 2 ways that MIGHT work.

    1. In the Post/CPT Listing page, select all the posts and click to edit them all at once. You will for sure have to increase the number of posts shown in each list page to minimize how many times you have to repeat the process to update all the posts.

    2. You can setup the loop for your Posts/CPT, either with a plugin or in your functions.php file of your activated theme, and make sure you remove the loop after you are done:

    Inside the loop, you can try something like this:

    foreach( $posts_id as $post_id ){
    wp_update_post( $post_id );
    }

    Again, I did not try any of the 2 suggestions, hopefully and especially the second suggestion will work, and will force ACF to autoupdate the Calculated fields.

    Good luck, and please let us know if anything worked !

    Thread Starter peterbisset

    (@peterbisset)

    Thanks for the quick response.

    I’ve actually tried both of these suggestions however they do not update the field in the front end.

    I know the field is populated with a value because separately I am using a count field that uses the value of the calculated field:

    `$value = get_field( ‘field1_calculated’,$post_id );
    if ( $value ) {// if value is present
    $total += $value;// Add value.
    $count++;// Increase count by one
    }

    Any other suggestions as to how I could get this to populate on the front end?

    Plugin Contributor nick6352683

    (@nick6352683)

    That’s interesting… to make things clear from your response. The calculated fields get updated in the backsite, but not on the front end? Am I understanding you correctly?

    If that is in fact the case, we MIGHT be facing some caching issues. Even if you, or your hosting does not use caching, I am almost certain that ACF caches things (at least blocks, if not metaboxes as well), and I know Gutenberg caches things too (I think !).

    The bad news from me is that I can’t think of a quick solution for you right now, as I never had to solve a similar situation… That said, my suggestion to you would be to approach the ACF developers first, and then the Gutenberg team on Slack, and see if they have better insights than me for this issue.

    Thread Starter peterbisset

    (@peterbisset)

    OK, sorry slight mistake on my behalf, the count isn’t counting the calculated field it was counting something else.

    So, in fact the calculated field isn’t saving to the database at all, I confirmed this by checking phpmyadmin.

    Any other suggestions how I can get this to calculate automatically?

    Plugin Contributor nick6352683

    (@nick6352683)

    Sorry, at this point I’m out of ideas. Try reaching out to the ACF team to see if they have any suggestions, or ideas to why the calculated fields are not being updated by either of the 2 methods mentioned above. Otherwise this is indeed a huge problem when importing large amount of data and then creating the calculated fields, which I’m sure this is true in your case.

    Thread Starter peterbisset

    (@peterbisset)

    Thanks, I reached out to them previously but they said that I needed to ask you guys as they weren’t sure how your plugin is saving the data in the backend.

    Thread Starter peterbisset

    (@peterbisset)

    Hi, do you have any updates on this?

    Plugin Contributor nick6352683

    (@nick6352683)

    Sorry, I’m out of ideas right now, but I wonder if the developers of this plugin have any thoughts on this…

    Thread Starter peterbisset

    (@peterbisset)

    I tried contacting them, unfortunately they said you guys need to sort this out as it is not within their scope.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Automatic Update of Calculated Fields After Import of Posts’ is closed to new replies.