Support

Account

Forum Replies Created

  • Thanks John. Is there a way to only show these attachment fields when editing a certain field? The additional inputs I would like to add to the media items would only be relevant to that one field, not to all attachments in the media library.

  • By the way I also needed to clear the 2nd select’s value when the 1st select changed, so I just added this under the “acf.add_filter” javascript:

    				$( '#acf-field_648b0890a2462' ).on( 'change', function( e ) {
    	$( '#acf-field_648b0852a2448' ).val( '' ).trigger( 'change' );
    } );
  • Just in case it can help someone, I was able to accomplish this perfectly for my situation using Elliot’s select2_ajax_data filter suggestion and it’s much simpler than the other methods it seems. I have two taxonomy dropdowns and needed the 2nd one to be filtered by the value of the 1st one. @oscarfanatic ‘s solution got me pointed in the right direction and some other code I found online helped clear the rest up.

    Also want to tag @hube2 in case it can help with his awesome efforts of helping people out in the forums.

    Here’s how it works:

    add_action( 'acf/input/admin_footer', function() {
    	?>
    	<script>
    		( function( $ ) {
    			if ( typeof acf !== 'undefined' ) {
    				acf.add_filter( 'select2_ajax_data', function( data, args, elem, field, instance ) {
    					if ( 'field_648b0852a2448' === data.field_key ) {
    						data.format_id = $( '#acf-field_648b0890a2462' ).val(); // format_id is a custom property being added to the data object. It can be named whatever you want.
    					}
    					return data;
    				} );
    			}
    		} )( jQuery );
    	</script>
    	<?php
    } );
    
    add_filter( 'acf/fields/taxonomy/query/key=field_648b0852a2448', function( $args, $field, $post_id ) {
    	$format_id = $_POST['format_id'] ?? false; // $_POST['format_id'] is the custom property you created in the javascript above
    	if ( $format_id ) {
    		$args['meta_key'] = 'format';
    		$args['meta_value'] = $format_id;
    	}
    	return $args;
    }, 10, 3 );
  • @hube2 Sorry I missed your reply here. We’re exporting and then importing the field groups. I believe it also happens when duplicating or moving fields. It doesn’t happen consistently so unfortunately we can’t give steps to reproduce it.

    I’m curious, have you not heard anything else about this issue? I assumed other people must be experiencing it, since it’s been affecting both myself and another dev on multiple projects for the last few months.

  • FYI you can also do something like:

    the_field( 'repeater_3_phone' );

    The 3 here is a zero-based index, so this should output the phone field from row 4.

  • @hube2 Do you know if there’s been any progress on this? I use Message fields as a type of container for my own custom output, but it’s stripping out the HTML tags. Or is there a filter besides prepare_field I should be using? I’d rather not have to modify wp_kses_allowed_html.

  • I’m having the same problem on a non-multi-site WordPress install. I guess WordPress has extended this annoying “feature” to all installations.

  • I’m just wondering, since the Label is an optional field, and in this case omitting the label breaks the layout, why wouldn’t this be considered a bug? Shouldn’t ACF check if the label is empty and account for it?

  • Had to make an update since the post IDs weren’t being included in the custom relationship field’s results correctly.

  • What I ended up doing is extending “acf_field_relationship” with my own classname “acf_field_relationship_nogroup”. A few things needed to be customized, and I needed to register the new control in jQuery as well. It seems to be working well.

    Seems like not grouping the results by post type should be an option for Relationship fields though.

  • Hey John, sorry for bringing this up again, but since I was having a hard time explaining the issue, I decided to just poke around until I figured it out but I’m still having problems.

    I think a simpler explanation is that the default way of displaying my posts in the relationship field is like this:

    Bios
    Jack Brown
    Jane Smith
    John Doe
    
    Resumes
    Jack Johnson
    James Thompson

    But I need the results to simply display like this:

    Jack Brown
    Jack Johnson
    Jane Smith
    James Thompson
    John Doe

    So no grouping by post type. I’ve poked around in the code and the get_ajax_query function calls the function acf_get_grouped_posts which groups the results by post type, and as far as I can see there’s no way to bypass the grouping function. So I’m thinking I need to create a custom ACF Relationship field/plugin that doesn’t call the acf_get_grouped_posts. I just want to check in real quick and see if I’m missing something before doing that, since it’s not an ideal solution.

    Thanks you!

  • Thanks John. This looks like it can help with sorting the results for each post type, but can this also help with combining the posts from each post type into a single listing?

    Basically the real use case is that I have two post types: Bio and Resume. The Relationship field needs to show both post types combined into a single listing, not separated by post type.

    Maybe it would be best to duplicate the Relationship field and just create a new field based on it.

  • That’s a good idea! I wanted to keep all my “clonable” fields in their own field group, like “Library” or “Templates”, but I can just name them something like “Template > Call To Action” so at least they’re organized together. Thanks!

    Edit: I accidentally marked my own post as having solved the question instead of yours and can’t change it 🙂

  • That’s really good to know, thanks!! I definitely don’t want these filters to be applied when exporting.

  • Oh interesting. Yep, I frequently use load_field filters, although I always use them with the /key=field_XXXXXX params. I can’t say for the previous times I’ve had the issue, but this last time with the clone field I mentioned, there were no filters on any of those image fields.

  • This is a pretty common problem for me, and it happens on many different WordPress installs. I’d say it’s been happening for about a year, but it’s probably more like 1.5 years since Covid has screwed up my sense of time. I’m usually exporting locally and importing to a dev server. I always first delete the field group on the dev server, then import the json from my local install. The imported image fields will then only return IDs instead of arrays. It doesn’t happen with all image fields though. For the affected fields, I need to change them to return ID, save, then change back to array, save, and then the problem is usually fixed.

    This last one was being extremely stubborn and wouldn’t fix when changing the return type, but it was a somewhat unique use case. It was a disabled field group that was included in another field group as a Clone field (seamless replace). I deleted both field groups and reimported many times, and changed the return type many times. No matter what the image field would only return an array, not an ID (in this case I wanted the ID returned, not array.) Eventually I tried what I talked about above and that fixed it (exporting json, changing characters in the field key, and importing the modified json). Luckily I wasn’t using any hard-coded field keys anywhere so it immediately started working correctly.

    By the way, I want to add that when this problem happens, it always reverses the output type. If it’s set to an array, it will return an ID. If it’s set to an ID it will return an array. It seems to me that somewhere in the import process the return types get mixed up. The admin UI still shows the correct return type though (the correct radio button is selected), it just returns the wrong value.

  • This one was being really stubborn. Changing the field return type wouldn’t affect anything. Anyways, what I did was export the group to JSON, change a few characters in the image field keys, then delete the group and reimport the edited JSON. Then it starts returning the correct return type. Hopefully this is a reliable fix because this issue is extremely annoying and frequently breaks features when importing field groups between environments.

  • I have this problem a lot for some reason and what I just did to fix it was export my field group, then edit the JSON and change the field keys slightly. For example if the image field’s key is “field_6034ed0dca8ea” then I would change a few of the characters (hex chars only). Then I deleted the group and imported the edited one, and the value started returning correctly.

  • Forgot an important detail. When importing/exporting, if the image field is set to return an array it changes to return an ID. And if the image field is set to return an ID it changes to return an array. This literally just happened to me 30 seconds ago (latest version).

  • Thanks for your work on this Marc! I’ll give it a try when I need to clean up some field data.

  • Figured I’d add something to help people out who want to add a row to a flexible content field that’s inside of another flexible content field.

    acf.addAction( 'append', function( $el ) {
    	if ( $( $el ).hasClass( 'layout' ) && $( $el ).is( '[data-layout="level1_layout_name_here"]' ) ) {
    		var nestedFlexField = acf.getField( $( '.acf-field[data-name="NESTED_FLEX_FIELD_NAME"]', $el ) );
    		nestedFlexField.add( {
    			layout: 'level2_layout_name_here'
    		} );
    	}
    } );
  • This works for me:

    $( 'body' ).on( 'click', '.acf-fc-layout-controls .acf-icon.-minus', function( e ) {
    	$( this ).click();
    } );
Viewing 25 posts - 1 through 25 (of 41 total)