Support

Account

Forum Replies Created

  • 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?

  • Great!

  • 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?

  • I would loop through all the information and assign it to an array.

      Declare the array outside the loop.
      Add items to the array inside the loop and classify as expired or not.
      Sort the array by expire, date, title, etc.
      Loop through the array and output what you.

      The code below is UNTESTED, but it gives you an idea of how I would go about it.

    <?php
    
    //declare array
    $events = array();
    date_default_timezone_set('America/Los_Angeles');
    
    $today = strtotime(date('Ymd'));
    
    if (have_rows('events')): while (have_rows('events')) : the_row(); 
    
    //get the expire date
    	$expire = strtotime(get_sub_field('expire_on'));
    
    //compare it to today and assign it a value
     	if($expire < $today):	
    		$events[]['expired'] = true;
    	else:
    		$events[]['expired'] = false;
    	endif;	
    
    //assign the other information to key/value in the array
     	
    	$events[]['events_date'] = strtotime(the_sub_field('events_date'));
    	$events[]['events_title'] = the_sub_field('events_title');
        $events[]['events_location'] = the_sub_field('events_location');
    
    endwhile; endif; 
    
    //assign some variables for sorting
    foreach ($events as $key => $row) {
        $ev_expire[$key]  = $row['expired'];
        $ev_date[$key] = $row['events_date'];
        $ev_title[$key] = $row['events_title'];
        $ev_location[$key] = $row['events_location'];
    }
    //sorts by 'expired' (true first), then by date (descending), then by title (ascending)
    array_multisort($ev_expire, SORT_DESC, $ev_date, SORT_DESC, $ev_title, SORT_ASC,$events);
    
    //loop through the array and echo out the info if the event has expired
    
    foreach ($events as $event){
    
    		if($event['expired'] == true) {
         		echo "<div class='events-row expired'>";
           		echo "<h2>".$event['events_title']."</h2>";
           		echo "<h3>".date('Ymd',$event['events_date'])."|".$event['events_location']."</h3>
             </div>";
     		}
    
    }
    
    ?>
  • You have to use a front end form. The documentation is here.

    Basically, you change the settings below to fit your needs and add the acf_form($settings); where you want the form to appear.

    It involves programming, so you have to have access to the WordPress theme files.

    If you want this to appear on the Edit-tours.php page you have to add the coding to that file.

    This: <?php acf_form_head(); ?> goes at the top of your file ahead of get_header();.

    $settings = array(
    
    	/* (string) Unique identifier for the form. Defaults to 'acf-form' */
    	'id' => 'acf-form',
    	
    	/* (int|string) The post ID to load data from and save data to. Defaults to the current post ID. 
    	Can also be set to 'new_post' to create a new post on submit */
    	'post_id' => false,
    	
    	/* (array) An array of post data used to create a post. See wp_insert_post for available parameters.
    	The above 'post_id' setting must contain a value of 'new_post' */
    	'new_post' => false,
    	
    	/* (array) An array of field group IDs/keys to override the fields displayed in this form */
    	'field_groups' => false,
    	
    	/* (array) An array of field IDs/keys to override the fields displayed in this form */
    	'fields' => false,
    	
    	/* (boolean) Whether or not to show the post title text field. Defaults to false */
    	'post_title' => false,
    	
    	/* (boolean) Whether or not to show the post content editor field. Defaults to false */
    	'post_content' => false,
    	
    	/* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */
    	'form' => true,
    	
    	/* (array) An array or HTML attributes for the form element */
    	'form_attributes' => array(),
    	
    	/* (string) The URL to be redirected to after the form is submit. Defaults to the current URL with a GET parameter '?updated=true'.
    	A special placeholder '%post_url%' will be converted to post's permalink (handy if creating a new post)
    	A special placeholder '%post_id%' will be converted to post's ID (handy if creating a new post) */
    	'return' => '',
    	
    	/* (string) Extra HTML to add before the fields */
    	'html_before_fields' => '',
    	
    	/* (string) Extra HTML to add after the fields */
    	'html_after_fields' => '',
    	
    	/* (string) The text displayed on the submit button */
    	'submit_value' => __("Update", 'acf'),
    	
    	/* (string) A message displayed above the form after being redirected. Can also be set to false for no message */
    	'updated_message' => __("Post updated", 'acf'),
    	
    	/* (string) Determines where field labels are places in relation to fields. Defaults to 'top'. 
    	Choices of 'top' (Above fields) or 'left' (Beside fields) */
    	'label_placement' => 'top',
    	
    	/* (string) Determines where field instructions are places in relation to fields. Defaults to 'label'. 
    	Choices of 'label' (Below labels) or 'field' (Below fields) */
    	'instruction_placement' => 'label',
    	
    	/* (string) Determines element used to wrap a field. Defaults to 'div' 
    	Choices of 'div', 'tr', 'td', 'ul', 'ol', 'dl' */
    	'field_el' => 'div',
    	
    	/* (string) Whether to use the WP uploader or a basic input for image and file fields. Defaults to 'wp' 
    	Choices of 'wp' or 'basic'. Added in v5.2.4 */
    	'uploader' => 'wp',
    	
    	/* (boolean) Whether to include a hidden input field to capture non human form submission. Defaults to true. Added in v5.3.4 */
    	'honeypot' => true,
    	
    	/* (string) HTML used to render the updated message. Added in v5.5.10 */
    	'html_updated_message'	=> '<div id="message" class="updated"><p>%s</p></div>',
    	
    	/* (string) HTML used to render the submit button. Added in v5.5.10 */
    	'html_submit_button'	=> '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
    	
    	/* (string) HTML used to render the submit button loading spinner. Added in v5.5.10 */
    	'html_submit_spinner'	=> '<span class="acf-spinner"></span>',
    	
    	/* (boolean) Whether or not to sanitize all $_POST data with the wp_kses_post() function. Defaults to true. Added in v5.6.5 */
    	'kses'	=> true
    			
    );
    			
    
    	acf_form($settings);
Viewing 25 posts - 1 through 25 (of 67 total)

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.