You can explore the ACF Javascript API
Put this code in your functions.php file. Then, change the part “field_123abcf” below with the field key of the field you want to change the label
function my_acf_load_field( $field ) {
$field['label'] = "Place : ";
return $field;
}
add_filter('acf/load_field/key=field_123abcf','my_acf_load_field');
Great! Glad to help!
If the ‘filament’ field is a straight repeater, I don’t think you need the foreach loop:
try this:
$filamente = get_field( 'filament' );
if( $filamente ):
$data_filament_slugs = implode(",", array_column($filamente, 'slug') );
endif;
It might be better to use the update_sub_field function inside the save_post action.
So you would loop through the subfields grab the value, run your substr function, and update the other field with the new value.
Use the get_field_object function instead of the loop and you can return the [‘value’] as an array.
I think I accidentally deleted my response, so here it is again:
I would use jQuery for this and also add the tab to the field group beforehand. You’ll want to use the acf/input/admin_footer action.
It would look something like this:
add_action('acf/input/admin_footer', 'check_for_videos');
function check_for_videos(){
?>
<script>
var rowCount = jQuery('#acf-group_571814caa0f78 table tbody).find('tr');
if(rowCount ==0 ){
jQuery('tab field selector here').hide();
}
</script>
<?
}
It is sometimes difficult to nail down the exact name to use in the selector. For me it’s a trial and error thing.
You’ll want to use the acf/input/admin_footer action to run jQuery for this. Also, I would create the tab that you want in the field group.
Basically, you could look to see if there are rows in the body of that repeater field table then hide the tab if there are no rows . This script will get triggered when the edit post page is ready.
It would look something like this:
function check_for_videos() {
?>
<script>
var rowCount = jQuery('#acf-group_571814caa0f78 table tbody).find('tr');
if(rowCount.length == 0 ){
jQuery('tab field selector here').hide();
}
</script>
<?
}
add_action('acf/input/admin_footer', 'check_for_videos');
The most challenging part for me when doing this is getting the selector field correct to run the jQuery. If you’re not familiar with jQuery, you have to refer to the element that you want to run the script on and sometimes it’s hard to nail that down.
You may want to check that you’ve added acf_form_head(); function to your template file before the get_header(); function.
I don’t know if this makes a difference, but I usually have an array of strings for my field groups:
'field_groups' => array('group_5b97a105e7aa7','group_5b9944bf65405','group_5ba3c0692f67a','group_5b99428f53157','group_5b994530e2cc1');
How about:
function acf_prepare_field_set_print_max( $field ) {
$ID = get_the_ID();
$project_total_prints = get_field('project_total_prints',$ID);
$field['max'] = count($project_total_prints);
return $field;
}
add_filter('acf/prepare_field/name=print_nbr', 'acf_prepare_field_set_print_max');
I usually add a message field type and change the message with the acf/load_field filter:
function rosters_away_message($field){
$field['message'] = "<button style='color:white; background-color:beige' type='button' class='btn btn-success btn-sm'><a target='blank' href='http://'>Add new</a></button><br /><br />".$roster_final;
$field['label'] = " ROSTER";
}
return $field;
}
add_filter('acf/load_field/key=field_5929a3d8a859c', 'rosters_away_message');
How about:
function acf_prepare_field_set_print_max( $field ) {
$project_total_prints = get_field('project_total_prints');
$field['max'] = count($project_total_prints);
return $field;
}
add_filter('acf/prepare_field/name=print_nbr', 'acf_prepare_field_set_print_max');
You don’t need that outside acf/init action to do this.
Try this in your functions.php file (I changed the function name):
function acf_prepare_field_set_print_max( $field ) {
$project_total_prints = get_field('project_total_prints');
$field['max'] = $project_total_prints;
return $field;
}
add_filter('acf/prepare_field/name=print_nbr', 'acf_prepare_field_set_print_max');
I see what you are saying, but I thought it defaulted to the current post ID. Anyway, my fields are being populated now, whether I add a varible to the ‘post_ID’ or leave it as ‘false’.
The only fields that are not functioning properly are two post object fields in a group. I have tested that group on the form, but commented them out for now. They only display the value that has been selected on the backend.
$post_ID = get_the_ID();
$settings = array(
'id' => 'acf-form',
'post_id' => $post_ID,
'new_post' => false,
'field_groups' => array('group_56f97a1203bfe','group_58b8b6b885fbb'), //'group_57180f67b48be',
// 'fields' => array(),
'post_title' => false,
'post_content' => false,
'form' => true,
/* (array) An array or HTML attributes for the form element */
// 'form_attributes' => array(),
'return' => '',
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => __("Update", 'acf'),
'updated_message' => __("Post updated", 'acf'),
'label_placement' => 'top',
'instruction_placement' => 'label',
'field_el' => 'div',
'uploader' => 'wp',
'honeypot' => true,
'html_updated_message' => '<div id="message" class="updated"><p>%s</p></div>',
'html_submit_button' => '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
'html_submit_spinner' => '<span class="acf-spinner"></span>'
);
acf_form($settings);
Yes, I have the acf_form_head() function properly included, and no it’s not in a loop. I got the fields to show up by not using a registered acf form, however, my post object only shows the post selected on the backend and an “allow null” option (“-Select-“). Any thoughts?
Does the the post object populate without the filter on the front end?
On second thought, this probably won’t work for you,since I’m trying to limit my posts from thousands to lest than 50 and there’s no auto complete to narrow the selections.
I have a work around that seems to work for me. I use a select type field and load values into it using the acf/load field filter. It uses a key/value set up. I can give you an example tomorrow as it is past midnight here in Maine.
Have you tried specifying a field by name or key? Also, the two numbers that are at the end are missing from your code line. Not sure if they’re optional:
add_filter('acf/fields/post_object/query', 'sort_people');
// filter for a specific field based on it's name
//add_filter('acf/fields/post_object/query/name=my_post_object', 'my_post_object_query', 10, 3);
// filter for a specific field based on it's key
//add_filter('acf/fields/post_object/query/key=field_508a263b40457', 'my_post_object_query', 10, 3);
I tried to do a similar set up and was unable to get the query to work as well.
I’m not sure what you’re asking. When you create a front end form, there’s a button that says submit and ACF does the rest. Are you not seeing a button?
Noticed this line is missing the s in sort
add_filter('acf/fields/post_object/query', 'ort_people');
You need to find the ID of your field group.
Go to Tools in the Custom Fields menu, check the group that the fields are on and click the button that says generate php.then look for your field group ID It will start with ‘group_’.
Can you show me your code for the settings?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.