Support

Account

Forum Replies Created

  • This appears to be fixed with WC v3.0.1. Must’ve been a WC issue after all.

  • I have found this issue as well and believe it is caused by the new WC 3.0 CRUD classes. However, it does not happen with regular custom fields, only ACF custom fields. So I believe it is an ACF bug.

  • And now a brand new problem. Any idea why this would break the site when pushed to a remote server? It says the issue is with the “[” character on the line $pocket_name_fields = get_field('pocket_name', $post_id)[0];, but I don’t know why that would be.

    Databases are the same… field key is the same… what am I missing?

  • Follow up to my own question. I’ve got this working as desired, but I want to post my code below in case it’s useful to anyone, and to make sure I’m doing this right.

    
    function sk_acf_update_pocket_postdata( $value, $post_id, $field ) {
    	global $_POST;
    	
    	$pocket_name_fields = get_field('pocket_name', $post_id)[0];
      
    	$head_brand = $pocket_name_fields['head_brand'];
    	$head_name = $pocket_name_fields['head_name'];
      
    	$pocket_title = $head_brand . ' ' . $head_name . ' ' . $value;
    	$pocket_slug = sanitize_title( $pocket_title );
      
      $pocket_postdata = array(
        'ID'          => $post_id,
        'post_title'  => $pocket_title,
    	  'post_name'   => $pocket_slug
      );
      
      wp_update_post( $pocket_postdata );
    	
    	return $value;
    	
    }
    
    add_filter('acf/update_value/key=field_53f7a5369c2ab', 'sk_acf_update_pocket_postdata', 10, 3);
    

    I changed the field key I’m hooking into to the last sub field in the repeater. If I used the other two, it would only rewrite the title and slug after hitting update for a second time.

    Still seems a little strange and inelegant, but it’s working. I welcome feedback of any kind.

    BTW, thanks @Elliot for building and maintaining such an incredible tool. It has completely changed how I work.

  • I’ve got this working just as desired with regular text fields, but I’m having trouble doing it with a repeater. I’m using a repeater because the columns make the layout a lot cleaner, but there’s only a single row. The repeater has 3 sub fields, all text. Here’s my latest attempt:

    
    function sk_acf_update_pocket_postdata( $value, $post_id, $field ) {
    	global $_POST;
    	
    	$pocket_name_fields = $value[0];
      
    	$head_brand = $pocket_name_fields['head_brand'];
    	$head_name = $pocket_name_fields['head_name'];
    	$pocket_type = $pocket_name_fields['pocket_type'];
      
    	$pocket_title = $head_brand . ' ' . $$head_name . ' ' . $pocket_type;
    	$pocket_slug = sanitize_title( $pocket_title );
      
      $pocket_postdata = array(
        'ID'          => $post_id,
        'post_title'  => $pocket_title,
    	  'post_name'   => $pocket_slug
      );
      
      wp_update_post( $pocket_postdata );
    	
    	return $value;
    	
    }
    
    add_filter('acf/update_value/key=field_53f7a5039c2a8', 'sk_acf_update_pocket_postdata', 10, 3);
    

    The field key I’m using is for the repeater. I was using a field key for one of the sub fields, and was able to pull that value in successfully, but I wasn’t able to pull in the other two values using get_the_field_object.

    Any help would be greatly appreciated.

Viewing 5 posts - 1 through 5 (of 5 total)