Support

Account

Home Forums General Issues ACF data not showing in the front without a manual post update.

Solving

ACF data not showing in the front without a manual post update.

  • Ok, so I am having a very simple problem that I have spent hours trying to debug and hope someone can help.

    I have
    Post type – Location (bidirectional to company using a relationship box)
    Post type – Company (bidirectional to location using a relationship box)

    I imported custom data from csv using an import plugin. I am using acf extended to define the bidirectional relationship. I imported the location field using a relationship box into the company post type. I also have a company field in location post type which should auto update based on bidirectional relationship.

    In the frontend, I have two templates location.php and company.php, the company template works fine and displays the location. However until, I open the company post type and update the post manually, the location would simply not display.

    The solutions I have tried so far,

    Update all posts using the WP Cli
    sudo wp post update $(wp post list –post_type=’company’ –format=ids –posts_per_page=4000) –post_status=publish –allow-root

    This updates the post but the data does not appear in the front.

    Use a custom function without much success.

    // Retrieve all pages
    $my_posts = get_posts(array(
    ‘post_type’ => ‘company’, // Post Type: page
    ‘posts_per_page’ => -1,
    ));

    foreach($my_posts as $key => $my_post) {
    $meta_values = get_post_meta( $my_post->ID);

    foreach($meta_values as $meta_key => $meta_value) {
    update_field($meta_key, $meta_value[0], $my_post->ID);
    echo $my_post->ID ,”</br>” ;
    }
    }

    Stackoverflow thread with same issues and no answer
    https://stackoverflow.com/questions/41158413/wp-all-import-with-advanced-custom-fields-does-not-display-correctly-until-afte

  • You will need to create an action or filter that runs during the import, see this reference https://www.wpallimport.com/documentation/advanced/action-reference/ I’m not sure what filter to tell you to use here, but I think it would need to be “pmxi_saved_post”.

    WPAI does not call update_field() when importing ACF fields, it calls update_post_meta() directly, so anything added by the plugin that creates the bidirectional fields will be bypassed.

    So what you need to do is use the correct action/filter for WPAI and in your filter or action get the relationship field value and use update_field() to update that value which should cause the acf add on to perform it’s own actions to create the bidirectional entries needed.

  • Hi both, I am experiencing the same issue in a slightly different scenario. I believe that the error lies within the same core problem.

    I am generating posts using automation tools to populate and create Custom Posts that contain ACF fields. However, even though these posts are created a manual update is needed for them to shown on the front end ( Where I am using Oxygen, Repeater, ACF and FacetWP)

    I have tried updating the partnered variables like variable & _variable. I have gone so far as to try to utilise uncanny automaton to update the post once launched in order to allow those variables to show up to no avail.

    Is there any progress on a high level on this problem? or could either of you point me in another direction.


    @evilopinions
    @hube2

  • I have the same issue,

    New site. ACF is installed and my custom fields are imported from the themes acf-json folder.

    The ACF fields were exported from one site and imported into the other.

    I exported my pages from the old site, imported (standard WP Import) them into the new one.

    When I view the page on the backend I can see everything displaying correctly but nothing shows until I update the page.

    I don’t know if it helps, but none of the imported pages have content in the main body, they are 100% ACF pages.

  • Hi everyone,

    I am having the same issue. All import is good at backend but the shortcode info on front end is not showing if i not update each post manually :S

    I am importing woocommerce products with meta value, nothing all.

    Thank you

  • I am having the same issue.

    WP: 6.1.1
    WOO: 7.3.0
    PHP: 7.4.33
    ACF: 6.0.7

    I have imported all produces via CSV using WP-All-IMPORT

    The ACF value are populated and saved in the WooCommerce Product.
    This is evident when navigating to EDIT PRODUCT

    However the [value] [label] or [array] is not being out on the front end until the post has been [updated]

    2000 products – I’m not updating manually.

    ACF Button Group
    Choices
    value : Label
    value : Label
    value : Label

    returning value : (•) Label

    I have tried get_field && get_field_object (using array)

    value won’t return until the post is updated

    John – I can provide access to the site if needed

  • For those with issues, you cannot use the standard WP importer to import ACF relationship fields. ACF stores POST IDs in relationship fields. Post IDs will change when using this importer.

    As stated in my previous reply: The post that will be related must exist. You will need to hook into whatever you are using for doing the import and get the value of the relationship for the post and call update_field() for that field on the post being imported. The import must be done correctly in the first place, the import tool must be aware of ACF and it must create the field and the ACF field key reference in the database.

    The other plugin is designed to work with ACF and will not function with importing for many reasons, some of them mentioned above.

  • This reply has been marked as private.
  • @justin-graham I cannot provide hands on help. For that you would need to open a ticket by logging into your account. Not sure if the new devs provide that type of support or not.

    I would try changing your add_action() to include the variables provided by WC

    
    add_action('woocommerce_single_product_summary', 
                  'woo_display_custom_general_fields_values', 45, 2);
    function woo_display_custom_general_fields_values($post, $product) {
      .........
    

    and then supply ACF with the post ID in get field

    
    // example
    $parentSKU = get_field('parent_barcode_sku', $post->ID);
    

    If that does not work I would look in the database and make sure that WPAI is creating the correct field key references and storing the value correctly. If it is not then the issue is with WPAI.

  • Thanks John,

    I approached this a different way
    I changed the Choices from value : Label to just Choice Value

    Part Source:
    sh : SECOND HAND
    oem : OEM
    new : NEW

    Part Source:
    SH
    OEM
    NEW

    Used Admin Columns Pro 100 products per page, 15 pages – and bulk edited changing the value of the part source to “SH” along with other choice values “OEM” , “NEW”.
    Then in my PHP added the conditional on the output.

     global $product;
      $id = $product->get_id();
      $partsource = get_field ('part_source', $id);
    
      if( $partsource == 'SH') {
        echo 'SECOND HAND';
      } else {
        echo esc_attr($partsource);
      }
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.