Support

Account

Forum Replies Created

  • Recently this filter has stopped working for me with ACF. Is anyone having similar issues?

  • I found a workaround since the above solution wasn’t working for me, and is kind of a pain if using get_fields(). Turns out you don’t need to add any custom data to the preview. Turns out when fetching the preview, WordPress includes the fact that it is a preview within the $_POST params.

    So you can just set up the example like this when registering the block

    
    'example'           => [
      'attributes'  => [
        'mode'  => 'preview',
        'data'  => [],
      ]
    ],
    

    Then when rendering the content check if it is a preview like this

    
    if( ! empty( $_POST['query']['preview'] ) :
      /* Render screenshot for example */
    else :
      /* Render HTML for block */
    endif;
    
  • Not sure if anybody needs this, but I believe these reusable blocks are saved under core/block. So the above code should be changed to

    
    $post_type_object->template = array(
            array(
    			'core/block', array(
    				'ref' => 290,// Reusable block id
    			),
    		),
        );
    
  • Hmmm, I don’t seem able to update the term meta when updating acf values any longer. Anybody running into issues here?

  • Hey @edir, thanks for this.. really great. I am using this to update all of my meta fields instead of providing individual filters for each field, the only catch is that each field name has to be prefixed with “meta”. Here’s the code I am using:

    
    /**
     * Update term meta based on ACF term meta fields
     */
    function namespace_acf_update_term_meta( $value, $post_id, $field ) {
      $term_id = intval( filter_var( $post_id, FILTER_SANITIZE_NUMBER_INT ) );
    
      if( substr( $field['name'], 0, 5 ) === 'meta_' ) {
        if( $term_id > 0 ) {
          update_term_meta( $term_id, $field['name'], $value );
        }
      }
      
      return $value;
    }
    add_filter( 'acf/update_value', 'namespace_acf_update_term_meta', 10, 3 );
    add_filter( 'acf/update_value', 'namespace_acf_update_term_meta', 10, 3 );
    
    /**
     * Load term meta in for ACF meta fields
     */
    function namespace_acf_load_term_meta( $value, $post_id, $field ) {
      $term_id = intval( filter_var( $post_id, FILTER_SANITIZE_NUMBER_INT ) );
    
      if( substr( $field['name'], 0, 5 ) === 'meta_' ) {
    
        if( $term_id > 0 ) {
          $value = get_term_meta( $term_id, $field['name'], $value );
        }
      }
    
      return $value;
    }
    add_filter( 'acf/load_value', 'namespace_acf_load_term_meta', 10, 3 );
    add_filter( 'acf/load_value', 'namespace_acf_load_term_meta', 10, 3 );
    
  • Thanks, well as I said I did increase the max_vars as well as execution time in the php.ini but it didn’t do anything. If I find the solution I’ll make sure to post it here.

  • Hi James, thanks. Right, so it looks like it is a problem with the server. It is running into some sort of execution error after about 30 secs and taking me to a “service unavailable” page. Updated the max input vars as well as execution and input time in php.ini, but am still receiving the same problem. I also called support and they said suhosin was not enabled on the server and there wasn’t much else they could do.

    Simply uploading the acf-json directory in my theme won’t work either because I am using that reusable field group plugin and I lose it’s functionality when using only the acf-json. Syncing doesn’t work either because I run into the same problem on the server as when importing the json files directly.

    Also, debugging live is pretty much not an option. I can duplicate the install and all of it’s plugins on another server, but I think that might defeat the purpose.

    I guess I could manually build the fields, but in the long-run it’s just not a viable solution. Really scratching my head on this one…

  • For what it’s worth I found a workaround for anybody needing similar functionality. What I did was use the update_value filter to create custom meta data based on taxonomy term names. Here is a snippet of the code:

    
    function custom_acf_values(  $value, $post_id, $field ) {
    
    	// Set authors
    	if( $field['name'] == 'authors' && $value != '' ) :
    
    		$names = '';
    		$authors = $value;
    	    
    	  if( $authors ) :
    
    		  foreach( $authors as $author ) {
    
    		  	$sep = '; ';
    		  	if( $author == end( $value ) ) {
    		  		$sep = '';
    		  	}
    
    		  	$author = get_term( $author, 'authors' );
    		  	$name = $author->name . $sep;
    
    		  	$names .= $name;
    	  	}
    	  endif;
    	  update_post_meta( $post_id, 'poster-authors', $names );
    
    	endif;
    }
    add_filter('acf/update_value', 'custom_acf_values', 10, 3);
    

    However, I am still interested in learning more about the filter I mentioned in OP.

  • Agreed… global fields and field groups would be incredibly helpful.

  • Thanks Tibor… looks like this solution is necessary with the regular version of ACF as well. Hopefully the documentation will update soon.

  • Thanks Elliot, I knew it was simple. I forgot to make it a page template. Everythings working smooth now. Thanks again.

  • Sorry, it looks like everything will be easier if I just create a custom post-type for the testimonials with each post having its own custom fields. I didn’t know how to delete the comment. Just for curiosity’s sake if someone wanted to post a solution that would be great. Sorry again.

  • Sorry I haven’t gotten back to you Elliot, I had trouble signing on a few times but I think it was because it was from an insecure network. I actually got it to work by simply changing the field values. I don’t have any other custom fields with those values, so I’m not exactly sure what the problem was.

    But to confirm your questions, yes ACF was saving the first image but not others. I did remove and upload the image and it didn’t work. My guess is some issue in the database?

  • Hi Elliot,

    The reason why I don’t think it’s 1 or 2 is because I checked to see if “picture2” would save the image I used in “picture1”. The image worked fine for that field, so by the “picture2” field not saving it I’m guessing it’s something wrong with the plugin or database vs. the image.

    I’m sorry that I am pretty clueless when it comes to databases, so bear with any stupid comments or questions that follow. I searched my database and found a couple of rows which contain the value, 12 in wordpress_posts 11 of which are revisions, and 28 in wordpress_postmeta. In the postmeta table, I see a couple of different meta_values. For meta_key “_picture2”, the value is “field_5267ea8229947”. For key “picture2”, it’s “995”. Then there are two more keys “field_5267e896a6a10” and “field_5267ea8229947”.

    I have no idea if that helps at all, please let me know if you need anything else. Thanks again.

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