Forum Replies Created

  • Thanks @lgladdy!
    I will try this asap, sounds logical ๐Ÿ™‚

  • This is still an issue in 2020. Iโ€™m using the Gravityforms User Registration add-on to create users and populate acf fields with form data. In the backend on the user profile all the fieldvalues are there, the metafields are also present in the database.
    But the fields wonโ€™t show up in the WP Rest API or with get_field, unless I manually save the user profile…
    What should we do to make the fieldvalues available right away?

  • Ah duh! This line messed it up:
    'key' => 'field_' . uniqid()

    This is different on every page load…
    Is there a best practice on how many characters this key should be?

  • Sorry, not related in the end. Saving works now!

  • Not sure if this is the same problem I’m experiencing, but fields that I defined using the acf_add_local_field function are also not saving on my custom post types?

    I’m running:

    • WordPress Version 5.2.2
    • ACF Pro Version 5.8.2
    • Classic Editor Version 1.5

    Gutenberg editor is disabled.

  • Ok thanks for your reply!

    I thought I could use the acf_add_local_field instead for this, so I added the following action that displays my checkboxes correctly now:

    add_action('acf/init',	array(&$this, 'addServiceMatchMakerFilter'));
    public function addServiceMatchMakerFilter() {
    	if (function_exists('acf_add_local_field')) {
    		$posts     = new Posts();
    		$global    = $posts->getGlobalInfo();
    		$questions = $global['match_maker_questions'];
    		// Add field for each match maker question
    		if (!empty($questions)) {
    			foreach ($questions as $question) {
    				$choices = [];
    				if (!empty($question['choices'])) {
    					foreach ($question['choices'] as $choice) {
    						$value           = $choice['choice_value'] ? $choice['choice_value'] : $choice['choice_label'];
    						$choices[$value] = $choice['choice_label'];
    					'key'          => 'field_' . uniqid(),
    					'label'        => $question['label'],
    					'name'         => sanitize_title($question['label']),
    					'type'         => 'checkbox',
    					'parent'       => 'field_5d3ebbd2fef0c',
    					'choices'      => $choices,
    					//'layout'       => 'horizontal',

    However, when saving my post the values from these fields are empty again (also in frontend). Any idea why this is happening?

    Thanks, Toine

  • Did you ever figure this out? I want to achieve exactly the same!

    Right now, I have the following setup (I used item & collection to match your example);
    In my post type I have the following rewrite set:

    'rewrite' => array('slug' => 'item/%collection%'),

    And a function that replaces %collection% for the acf value:

    function setupItemPermalink($post_link, $id = 0) {
    	$post = get_post($id);
    	if (is_object($post) && get_post_type($post) == 'item') {
    		$collection = get_field('item_collection', $post->ID);
    		if ($collection) {
    			$collection = get_post($collection[0]); // get first in array
    			return str_replace('%collection%' , $collection->post_name, $post_link);
    		} else {
    			$other = sanitize_title(__('not-in-collection', 'mydomain'));
    			return str_replace('%collection%' , $other, $post_link);
    	return $post_link;
    add_filter('post_type_link', 'setupItemPermalink', 1, 3);

    This part works! When I use the_permalink for an item, it outputs:

    But I’m not sure how I should setup my rewrites?
    This is not working:

    global $wp_rewrite;
    $item_structure = '/item/%collection%/%item%/';
    $wp_rewrite->add_rewrite_tag('%item%', '([^/]+)', 'item=');
    $wp_rewrite->add_permastruct('item', $item_structure, false);

    Any ideas?

  • +1
    As a workaround, it would be great to have an option to choose the output as HEX or RGB. That way, you can at least use it in CSS to add the opacity.

  • Sorry, I spoke too soon…
    I think the query itself works, but the post order is all messed up.
    The posts with both start and end date are in between the posts with only a start date in the wrong order.

  • Wow thanks, that works perfectly!
    I ended up doing this:

    /* Ongoing Past Events */
    $ongoing = new WP_Query( array(
      'post_type' 	 => 'event',
    	'meta_query'   => array(
      	'relation'      => 'AND',
          'key'         => 'acf_event_date_start',
          'value'       => date('Ymd'),
          'compare'     => '<',
          'type'        => 'date'
          'key'         => 'acf_event_date_end',
          'value'       => date('Ymd'),
          'compare'     => '>=',
          'type'        => 'date'
    	'orderby' 		=> 'meta_value_num',
    	'order'       => 'DESC'
    if ($ongoing->have_posts()) :
      $exclude = array();
      while($ongoing->have_posts()) : $ongoing->the_post();
        $exclude[] = $post->ID;       
    /* Past Events */
    $paged    = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query( array(
    	'post_type' 	 => 'event',
    	'post__not_in' => $exclude, // Exclude ongoing past events
    	'meta_query'   => array(
          'key'         => 'acf_event_date_start',
          'value'       => date('Ymd'),
          'compare'     => '<',
          'type'        => 'date'
    	'orderby' 		=> 'meta_value_num',
    	'order'       => 'DESC',
    	'paged' 			=> $paged

    Which also works, but you need 2 queries which is not ideal.
    Thanks for your help!

  • A year has passed, nobody interested in this feature?

  • @John Huebner:
    Thanks for your code! This works great, however there were 2 minor syntax errors in your code. Updated code:

    function post_updating_callback( $post_id ) {
      $repeater  = 'page_sections'; // the field name of the repeater field
      $subfield1 = 'page_section_title'; // the field I want to get
      $subfield2 = 'page_section_slug'; // the field I want to set
      // get the number of rows in the repeater
      $count = intval(get_post_meta($post_id, $repeater, true));
      // loop through the rows
      for ($i=0; $i<$count; $i++) {
        $get_field = $repeater.'_'.$i.'_'.$subfield1;
        $set_field = $repeater.'_'.$i.'_'.$subfield2;
        $value     = get_post_meta($post_id, $get_field, true);
        $new_value = sanitize_title($value);
        update_post_meta($post_id, $set_field, $new_value);
    add_action('acf/save_post', 'post_updating_callback', 20);

    Thanks a lot!

  • This appears to be a serious bug, rolling back to version 5.1 seems to work too.

  • Same here!
    After updating to ACF Pro 5.1.1, have_rows('repeater_field_name') returns true even with no rows in the repeater/flexible content field. This is a serious bug…
    Had to roll back to 5.1.

  • Thanks Elliot!
    I can confirm the fix works!

  • Any word on an update with proper fix?

    I don’t know, are we supposed to report the bug somewhere or are the developers reading the support forums too?

  • Glad to see I’m not the only one ๐Ÿ™‚
    I can confirm supernovae’s quick fix, however this doesn’t work with SVG images unfortunately…

  • You’re right, I didn’t even try it myself presuming this would work, but it doesn’t! You CAN make a whole new ACF group based upon a taxonomy term rule by the way, but that clutters up your ACF groups a lot…

  • I would love to see this integrated as well! I have been using Posts 2 Posts plugin for a very long time now on dozens of projects and it’s absolutely one of the best WordPress plugins hands down!

    However I try to avoid using a lot of different WP metaboxes in the WP admin area for my clients. The Posts 2 Posts adds a metabox for every connection, it would be so cool to be able to add these boxes in the ACF interface with the other custom fields. Could this be possible somehow?

  • I would love this feature too! Now, the only way to show or hide some fields based upon the taxonomy value is to make a radio button or checkbox field and use that as the conditional logic which seems a bit of a detour…

  • Well, the main disadvantage of the repeater field approach in my opinion is that if you (accidentally) trash your page where the custom gallery fields are in, you loose all of your galleries. That will never happen with seperate post types.
    Thanks for the update!

  • Although I ended up using a custom post type for this instead of a repeater field, this is a very useful piece of code!
    Thanks jnicol!

Viewing 25 posts - 1 through 25 (of 32 total)