Support

Account

Forum Replies Created

  • Ok thanks. Ajax was not even called before though. But no console errors of other JS that would stop JS from working. Anyway….

    Today I went to look into it and its magically fixed itself and its using ajax as it should and shows the error on the same page fine ヽ(ಠ_ಠ)ノ

  • I’m sorry I should have said…

    There are no WordPress or php errors with debug enabled or in the server error log.

    There are no console errors, I can’t see Ajax even being called.

    The validation works, because it does show the error “Categories is required”. Thats why we get the error because a required field is left blank that’s all.

    Thanks

  • Actually sidebar does not hide when changing it in screen options. I can see that is also a ACF issue by maxing out the width of the boxes to 1440px, which prevents the WP feature of hiding the sidebar working. Setting the following also fixes it:

    .post-type-acf-field-group .metabox-holder.columns-1 #acf-field-group-fields, .post-type-acf-field-group .metabox-holder.columns-1 #acf-field-group-options, .post-type-acf-field-group .metabox-holder.columns-1 .meta-box-sortables.ui-sortable, .post-type-acf-field-group .metabox-holder.columns-1 .notice
    {
        max-width: 100%;
    }
  • Setting the following to 100% max-width instead of max 600px fixes it on larger screens. We can then also remove the sidebar on smaller screens. No reason to have it max at 600px.

    .acf-admin-single-field-group .acf-field-object-flexible-content .acf-is-subfields .acf-field-object .acf-label, .acf-admin-single-field-group .acf-field-object-flexible-content .acf-is-subfields .acf-field-object .acf-input
    {
        max-width: 100%;
    }
  • I have done it. So if you want to create Select values on the fly you can use this code. This code saves the “value : Label” though which is what I need. It sanitises the value you enter to slugify it, so its saved as “my-customer : My Customer” in ACFs field choices. If the value is to be the label its easily adapted.

    You need to create a new text field for the “New” value you want to add. Then grab the old and new acf field_ids to use in the code.

    function amity_pre_save_post( $post_id )
    {
    	// Assign the field IDs to variables
    	$select_field_id = 'field_6346f63fec6c2';
    	$select_new_field_id = 'field_634ac0abf3d60';
    	
    	// IF the new field value post cintains a value, then proceed
    	if(isset($_POST['acf'][$select_new_field_id]) && $_POST['acf'][$select_new_field_id] != '')
    	{
    		// Assign the new value to label and value
    		$label = $_POST['acf'][$select_new_field_id];
    		$value = sanitize_title($label);
    		
    		// Get the ACF field settings
    		$field = get_field_object($select_field_id);
    
    		// Add the new fields value and label to the field settings
    		$field['choices'][$value] = $label;
    		
    		// Update ACF field settings - adds new value into Select fields Choices in DB
    		acf_update_field($field);
    		
    		// Asssign the Select field value to the new field value
    		$_POST['acf'][$select_field_id] = $value;
    		
    		// Clear the new field value as we want it blank every time
    		$_POST['acf'][$select_new_field_id] = '';
    	}
    }
    add_filter('acf/save_post' , 'amity_pre_save_post', 1, 1 );
  • The only other idea I have is use acf/save_post to check a new text field value in the post, and if it exists, assign that to the Select drop down, but also save it in the database to the ACF field Select setting values. I might look into that.

    Perhaps this post helps https://support.advancedcustomfields.com/forums/topic/updating-field-settings-in-php/

  • I did add some code that allows them to choose from a list of values in the database and then populate a text field by clicking one of those values. That works like a tag cloud (although I am only allowing one entry), but I realised I dont have the value slug saved and hidden behind the scenes. If interested here is the code that could be adapted into a Select dropdown but it doesn’t save the slug. Maybe I can with further code:

    function modify_project_field( $field )
    {
    	global $wpdb;
    
    	$projects_array = $wpdb->get_results("SELECT DISTINCT meta_value FROM $wpdb->postmeta pm WHERE meta_key = 'my_project'",ARRAY_A);
    	
    	foreach($projects_array AS $project)
    	{
    		$projects[] = $project['meta_value'];
    	}
    	
    	foreach($projects AS $project)
    	{
    		$project_links[] = '<a href="#" class="my-select-value" data-value="'.$project.'">'.$project.'</a>';
    	}
    
    	if($project_links)
    	{
    	    echo '<p>Enter a new value or choose from existing:<br/>';
    	    echo implode(', ', $project_links).'</p>';
    	    
    	    echo "
    	    <script>
    	    jQuery('.my-select-value').on('click', function()
    	    {
    		    var field = jQuery('#acf-field_6346f63fec6c2');
    			var value = jQuery(this).attr('data-value');
    			field.val(value);
    		});
    		</script>
    	    ";
    	    
    	}
    }
    add_action('acf/render_field/key=field_6346f63fec6c2', 'modify_project_field');
  • The checkbox option does not work anyway, because if you add for example “red : Red” then it actually saves the value AND label as “red : Red” and does not save the value “red” with label “Red”.

    I am trying to figure out how I can allow my customer to enter a value in a post which is then re-displayed later in other posts as an option. So they can build up values on the fly. I really dont want them editing the ACF field settings to add in new options. So almost like a tag cloud. I am surprised there is no tag cloud field. We cant use taxonomies as its only to show on a few pages. But I need to reference its slug in the code, so I need them to add something like “my-customer : My Customer” and then when they add a new post its showing “My Customer” in the drop down and saves using value “my-customer” because I need to reference the slug later not value.

  • Appreciate this is very old, but this code still works and I just wanted to say thank you this is fantastic! It would be great to have it in the core, even if just to prevent custom code breaking in the future. Still works now though! Thanks

  • I have a custom text field in which the data needs to have multiple spaces on the end. Its a special ID number for a 3rd party system we are integrating with WooCommerce products, and that systems IDs need to be packed up to 48 characters, if the actual ID characters do not add up to 48 then the rest is packed with spaces to fill it.

    It saves into the database OK with 48 characters and the ending with spaces, but when we load it on the product edit screen, all the end spaces are removed. Any spaces within any characters are kept, but the end ones are truncated.

    This means when saving the page, the spaces are removed in the database and then ID numbers wont match.

    How can we ensure ACF loads the exact data from the database and does not strip anything out not even spaces?

    Thanks

  • get_sub_field(‘whatever’) is not working for me when in Preview mode, and the page is Draft. When I publish it it works. When go back to draft they are empty.

  • Yes that makes sense, but such a shame it works this way. I wonder if I can add the duplicates as value1, value2 etc. and then enter the Label the same, so Value as the label for each one.

  • Your original code above seems to be working OK if I change:

    get_sub_field('text');

    to

    echo the_sub_field('text');

    I guess the_sub_field() uses get_field() but get_sub_field() doesn’t?

    So working Ok now!

  • I am trying to create my own function as follows, to replace the_sub_field() in the template, but it returns the value twice.

    function the_sub_field_wpml($field)
    {
    	$the_value = the_sub_field($field);
    	
    	if($the_value == '' || !$the_value)
    	{
    	
            //set the current language to EN temporarily
            add_filter('acf/settings/current_language', function(){return 'en';});
    
            $the_value = the_sub_field($field);
    
            //set it back to DE
            add_filter('acf/settings/current_language', function(){return 'de';});	
    	
    	}
    	
    	
    	return $the_value;
    }
  • Thanks but I dont think this works… we want to run have_rows() in the current language the user is on, because there could be options added in that language, in which case we want to show them. Only when there are no values in that language do we want to show the english. This is because WPML is not copying the site options so they are all blank.

    So putting the language change before have_rows() wont work, because it will always return the english wont it?

    I was hoping to find some conditional that says if the value does not exist to get the value from the english.

    Thanks

  • This is great, thanks a lot, will give it a go.

    But are we able to tell if a field is a sub-field? Some of my values use get_sub_field() so not sure how to tell if the field needs get_field or get_sub_field. The above code is not working on all my values just because some use get_sub_field but the code uses only get_field

    Saying that, it doesn’t work when changing it to get_sub_field anyway. Is it because its in a loop? Here is one such code for example, that I need to display the English content if the translation does not exist.

    <?php
    if( have_rows('enquire_link', 'option') ):
    	while( have_rows('enquire_link', 'option') ): the_row();
    ?>
    		<a href="<?php the_sub_field('link'); ?>" class="enquire-button">
    			<?php the_sub_field('text'); ?>
    		</a>
    <?php
    	endwhile;
    endif;
    ?>

    So in the above, the have_rows() check is false, nothing in the loop is being executed so probably does not even get to your acf/load_value hook.
    Thanks

  • But if you tell WPML hey I’m not trying to translate those field groups, let them in… they should show up.” -> OH REALLY???! Wow, thats great, thats exactly what I was looking for. Its confusing because we DO want the field content to be translatable. So we ticked “Make ‘Field Groups’ translatable” because we assumed it means we can then add multilanguage content for them. But what the checkbox actually means is do you want the labels translated, and it also makes the field groups separate across languages. So it looks like unchecking this box makes the fields available across all languages. So if this works well then thats fantastic and I am glad I raised this question now, we would have been explaining to the customer how to duplicate fields in order to enter the translated ACF content.

    Thanks

  • hi goldhat, yes I think you must misunderstand me, or I am misunderstanding ACF…

    Unless I’m really misunderstanding the problem this video at about 1:38 shows the English field group being duplicated to Spanish the same as any other post types.” -> the problem is this is a manual process and customers are asking why they have to do this. If we have all the extra content fields in English, people are asking why when they create a new language are the fields not there already. Editors/customers do not know about ACF, this is a developer tool to add content. They just see the content fields and think they will be there when they create new posts in the new language, but the fields are not there. The duplication process is technical. People are worried about doing it.

    But I’m not sure what the benefit is to translation of field groups other than the labels in the WP admin?” -> We are not translating labels. We are translating the field contents. If I create a new language, the ACF fields are missing from the new language pages and posts, so the website administrators cannot add the translated content. Not until the fields are manually duplicated to the other languages.

    Otherwise for the front-end why not just use English fields, any content entered can still be translated.” -> I dont understand this. It can only be translated after the field groups are manually duplicated to the other languages. What I am asking is can the field groups be automatically duplicated when you create a new language (some sort of hook you can use?)

    not sure how often field groups are actually being translated” -> Surely field groups are translated in every language? Why would a new language not have any custom fields?? Customers would like the same custom fields available to translate in the other languages. If I add a WYSIWG field for something like “Second Body Content” that would need to be in all the languages posts.

    I think the sync feature would be great if you add a field to English it duplicates that field to the translated versions. That would be a timesaver for sure.” -> yes

    I think it’s normal for that to be an additional plugin specific to bridging ACF/WPML” -> no way, not another plugin to add features to ACF. ACF should do this. Its nothing to do with WPML, its a feature of ACF, to be WPML compatible.

    Certainly it would not be good for performance to have ACF presume you want translate field groups” -> it would only happen at the time of creating a new language and a new field.

    Edit: I would just like to add that I think ACF is fantastic for a single language WP website. Its a plugin we will use on all sites. I come from an Expression Engine and Craft background, and ACF means that WP can be made to be just as powerful (more powerful) than those CMSs. Its only with WPML that ACF has problems for us, due to not creating the fields in the other language automatically. Toolset Types does it. I read on forums that WPML recommend Toolset Types as its more compatible.

  • Hi James, are you not with ACF, and does ACF not monitor these forums or provide support on them??

  • Hi James
    I do need to translate them though. I understand about them being posts, but Toolset Types shows its fields on a new language without duplicating, its automatic and I think ACF needs an option to do that too. It would be best to just have the fields in all entries when you create a new language so you dont need to duplicate them every time. It would also be best when adding a new field that that is also copied across in the other language field groups automatically (or have an option to).

    This would then make ACF much more compatible with WPML as its not very at the moment due to the manual duplication and missing new fields.

  • Thanks, but if I don’t translate it, the ACF fields do not appear on the translated entries. I have to translate the field group by duplicating it to each language in order to have them appear on an entry in the other languages.

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