Forum Replies Created

  • This is the final solution I’ve come up with. I found the function which returns all the local fields, compared them to the field groups I expected in my plugin, then looped through the names, breaking out of the loop on the first match.

    I doubt this will work in most setups, duplicate names are a possibility, you could probably check against the 3rd parameters $post_id for a post type, then the post type against $local->groups and each groups location parameters. #worksForMe

     * Get local field by name
     * @param String $reference 	- Field unique ACF key
     * @param String $field_name 	- Field nice name/slug
     * @return String $reference
    function get_field_by_name( $reference, $field_name ) {
    	$local_fields = acf_local();	// Grab all local fields
    	// Ensure we have local fields to work with
    	// Ensure that reference is empty
    	if( empty( $local_fields ) || ! empty( $reference ) ) {
    		return $reference;
    	// Loop through groups
    	foreach( $local_fields->fields as $key => $field_arr ) {
    			* Ensure the field is in our expected groups.
    			* Removed when not in the context of plugin
    			* $this->field_group_keys = array( 'group_xyz' ) - Holds array of expected local field groups
    		// if( ! in_array( $field_arr['parent'], $this->field_group_keys ) ) {
    		// 	continue;
    		// }
    		// Break the loop on first found match
    		if( $field_name === $field_arr['name'] ) {
    			$reference = $key;
    	return $reference;
    add_filter( 'acf/get_field_reference', 'get_field_by_name', 100, 2 );
  • Whenever passed by name it can’t seem to get the field key from acf_get_reference(). It’s got 3 filter hooks though, any suggestions on functions I could use to simply load all my cache all my local fields and/or start searching through my local field names for a key?

  • The solution is a bit messy and filled with a bunch of my classes functionality that won’t make much sense.

    The gist is that:

    • Repeaters need an integer count of expected subfields returned as a value from this hook.
    • Subfields names are prefixed with the parent repeater name.

    What I did was check the field type against ‘repeater’ and returned my custom database value count. At the top of the hook I checked if the $field[‘parent’] was empty, if not I used get_field_object( $field['parent'], $post_id, false, false ) to get the parent field name that the subfield are prefixed with.

    Once I returned the count to the repeater and stripped the parent name prefix off the subfields I was able to prepopulate the repeater with my custom table data. I have no idea if this will be helpful to anyone but at least it’s no longer a niche issue on the forums here.

  • What I had was an ACF form on a frontend page where the user could create new posts. Something like this:

    acf_form( array(
    	'form'			=> true,
    	'id'			=> 'prefix-acf-form',
    	'post_id'		=> 'new_post',
    	'new_post'		=> array(
    		'post_type'		=> 'post_type_here',
    		'post_status'	=> 'publish',
    	'field_groups'	=> array( Class_Here::get_acf_key( 'edit' ) ),
    	'honeypot'		=> false,
    ) );

    The idea being that I would save post_content field as the actual post content for the post.

    The problem was that I was using global $post, so the pages content was being displayed instead of the expected nothing.

    The solution was to check if the passed $post_id is either empty or new_post and if it is, return the value early before attempting to get the post content.

     * Return post content if possible
     * @param String $value - Field content
     * @param Mixed $post_id - Post ID, Empty, or 'new_post'
     * @return String - Post content for given post ID
    function themeprefix_acf_post_content( $value, $post_id ) {
    	// We already have a value for some reason, return it.
    	if( ! empty( $value ) ) {
    		return $value;
    	// We do not have a $post_id to pull from, return early.
    	if( empty( $post_id ) || 'new_post' == $post_id ) {
    		return $value;
    	return get_post_field( 'post_content', $post_id, 'edit' );
    add_filter( 'acf/load_value/name=post_content', 'themeprefix_acf_post_content', 10, 2 );
  • I’m pretty sure ACF automatically updates the same with WordPress plugins and themes. I believe the error was on my part – someone chime in if I’m wrong.

  • Got it, the issue is even though I’m adding an alias for jQuery I still need document ready. Even with dom ready I couldn’t get the acf js filter to work as expected:

    jQuery( document ).ready( function( $ ) {
    	let $datepicker = $( '#acf-field_5b16a9d5df47c + .hasDatepicker' );
    	$datepicker.datepicker( 'option', {
    		maxDate: new Date()
    	} );
    } );
  • I can’t for the life of me get this to work. I’ve been trying methods all over the forums. That is the correct hook I should be using, right? I can get console.log() from the above and below:

    ( function( $ ) {
    	$( '#dp1528832081239' ).datepicker( 'option', 'maxDate', 0 );
    	// $( '.field_5b16a9d5df47c .acf-date_picker input.input' ).datepicker( 'option', 'maxDate', 0 );
    } )( jQuery );
  • No idea if this will help others ( as it is an old topic ), but this is what I came up with to solve a similar issue. I needed a hidden value that would act as a slug to pull in other templates.

    Added a radio button control which asked the user to display or not to display this specific section. “Show Section” held the value of the hidden slug I needed to pull and would also be defaulted to this value, otherwise without the value the section would be skipped entirely and not shown.

    my-slug : Show Section
    0 : Don’t Show Section

  • This link is broken / no longer exists 🙁

  • After some searching, ACF doesn’t make this possible out of the box. Wouldn’t be a terrible idea to add it but I understand why they don’t. Or at the very least, give the thickbox left-hand menu options ( like “Add Media” does ) so you can add in objects with URLs or compatible with External Media Library plugins ( which automagically pull videos from channels for you to use ).

    Anyway, the idea is that you need the oembed objects ( vimeo / youtubes ) as Media Objects so they’re accessible from the media library. This is not a common gripe but luckily there are a few plugins out there that make it happen.

    Add External Media is a relative small, not used very much plugin which does exactly that at which point I was able to add the video to the gallery, get it, and display it as normal.

    The only caveat is, since the “Add to Gallery” button doesn’t give us access to the normal media left-hand links, add it using a separate method like the posts “Add Media” button before you have access to add it to The Gallery. It is kind of a hassle but not as much as creating a bunch of secondary fields and interweaving them with the gallery.

    Hopefully this helps future readers!

  • Thanks @acf-support I’ve submitted my request to their forums. Since there’s nothing really to solve here I’ll mark it as so.

  • Any progress on this? I’d also like to add in some of my default colors, even if I can’t do it through the panel I’d like to do it via a hook if possible.

Viewing 12 posts - 51 through 62 (of 62 total)