Support

Account

Forum Replies Created

  • Works with WP 5.5.3 too. Thank you all.

  • Same problem here, with WP 5.5.3 / ACF 5.9.2 / Classic Editor 1.6 (unset $_GET[‘preview’] works).

  • With acf javascript hooks, it’s now easy to save zoom.
    All you have to do is to put in your admin JS :

    ;(function($) {
    
    if ( typeof acf != 'undefined' ) {
        // Save Google Map zoom
        acf.add_action( 'google_map_init', function( map, marker, $field ) {
          // Create input to save zoom
          if ( $field.find( '.acf-hidden .input-zoom' ).length === 0 ) {
            $field.find( '.acf-hidden' ).append( '<input name="acf['+$field.data('key')+'][zoom]" value="'+$field.find('[data-zoom]').data('zoom')+'" class="input-zoom" type="hidden">' );
          }
          // Listen for zoom change
          google.maps.event.addListener( map, 'zoom_changed', function( e ) {
            this.$el.find('.input-zoom').val( this.getZoom() ).trigger('change');
            });
          } );
    }
    
    })(jQuery);

    No need to code extra PHP.
    I’m sure you can also easily save map type.

  • Same need here. It would be great if one day, ACF can do that.

  • Ok. Thank you. It’s done. Ticket submitted.

  • Hi. I know I can create own rule, this is very useful and I often use it. But why create something that already exists ? Is there any reason I don’t know that explains why ACF gets all children of a page as WP_Post objects only to see if there is one child ?

    Your code works well, but in my case, it filled my php memory and broke my page.

    I made some more tests and in my case, your location rule code runs only once and takes around 2.5 seconds (!)… with the code above it takes around 0.0010 second.

    I think it can be a good improvement for all ACF users & lovers like me.

    Thank you for your consideration.

  • If someone is looking for a solution, here’s how I did with bash script :

    # get plugin path
    acf_zip_file=”$(wp plugin path)/acf-pro.zip”

    # get acf zip file
    wget -O ${acf_zip_file} “http://connect.advancedcustomfields.com/index.php?p=pro&a=download&k=<YOUR_KEY>&#8221;

    # install & activate acf
    wp plugin install ${acf_zip_file} –activate

    # remove zip file
    rm ${acf_zip_file}

  • It seems that the problem is linked to a custom filter I added to sanitize_title that doesn’t allow underscores and convert them to dashes.

    The problem is that ACF checks for field key to be like “field_***” (function function acf_is_field_key() in api/api-field.php) ; so if the field key is “field-***”, it doesn’t work.

    Another solution is to activate local JSON so your field key can be what you want. Just create a folder name acf-json on your theme folder and re-save your field group.

  • After some tests, I realize that in group fields, ACF create fields named “field_***” (used for post_name) but after saving post_name become “field-***”.
    The reason is that wp_insert_post() (used for creating field) sanitize post_name with sanitize_title function (check wp-includes/post.php on line 3189).

    To prevent this, I have to add a filter to return original post_name.
    In advanced-custom-fields-pro/api/api-field.php, I add in function acf_update_field() on line 839 :
    add_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100, 3 );
    just before :
    $field['ID'] = wp_insert_post( $save );
    and remove that filter just after saving :
    remove_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100 );

    And after acf_update_field :

    function acf_update_field_sanitize_title ( $title, $raw_title, $context ) {
        return $raw_title;
    }

    It seems to work for me…

    Note :
    if you don’t want to alter ACF sources, you can add this to your functions.php :

    function acf_update_field_sanitize_title ( $title, $raw_title, $context ) {
      return $raw_title;  
    }
    
    // add filter for sanitize_title
    add_filter( 'acf/update_field', function ( $field ) {
      add_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100, 3 );
      return $field;
      }, 10, 1 );
    
    // remove filter for sanitize_title
    add_filter( 'wp_unique_post_slug', function ( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
      remove_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100 );
      return $slug;
      }, 10, 6 );
  • I had a similar problem, but it was not only on upgraded fields ; but also on new created fields ; nothing saved.

    I found that it was the post_name which cause problem.
    — post_excerpt is a readable slug
    — post_name is a string starting with “field-”

    If I change post_name to start with “field_” ; I was able to save my data.
    I just run this SQL query and everything seems to work :

    UPDATE wp_posts SET post_name = CONCAT( 'field_', SUBSTR( post_name, 7 ) ) WHERE post_type = "acf-field" && post_name LIKE "field-%"

  • Or you can prevent accidental change of the zoom when scrolling by disable this feature ; just add in the map options :
    scrollwheel: false

  • Maybe I’m wrong but I’ve the latest version of ACF and you can set a initial zoom to a field, but when you fill your google map field, coordinates are saved but not the zoom.

    The code above allows zoom to be saved.

    To save zoom even when not modified, I made this little change :

    In core/fields/google-map.php
    I added in create_field :

    $field['value'] = wp_parse_args($field['value'], array(
    	'address'	=> '',
    	'lat'		=> '',
    	'lng'		=> '',
    	'zoom'		=> $field['zoom']
    	));
  • For a project i need to save the zoom of a google map field.
    So i do this :

    In core/fields/google-map.php
    I added in create_field :

    $field['value'] = wp_parse_args($field['value'], array(
    	'address'	=> '',
    	'lat'		=> '',
    	'lng'		=> '',
    	'zoom'		=> ''
    	));

    and

    $keys = array( 
    	'data-id'	=> 'id', 
    	'data-lat'	=> 'center_lat',
    	'data-lng'	=> 'center_lng',
    	'data-zoom'	=> 'zoom'
    	);

    And in js/input.js

    // value exists?
    	var lat = this.$el.find('.input-lat').val(),
    	    lng = this.$el.find('.input-lng').val(),
    	    zoom = parseInt(this.$el.find('.input-zoom').val());
    
    if( zoom )
    {
        this.map.setZoom(zoom);
    }

    and

    google.maps.event.addListener( this.map, 'zoom_changed', function( e ) {
    	// reference
    	var $el = this.$el;
    
    	var zoom = this.getZoom();
    
    	// update input
    	$el.find('.input-zoom').val( zoom ).trigger('change');
    	});

    And it works.
    Hope this help.

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