Support

Account

Forum Replies Created

  • @spartieee i sent a support email to try and get a solution.

    Elliot replied with the following suggestion

    ACF will add fields after the ‘comment’ (textarea) field.
    It’s not possible to modify this behaviour by PHP, however, it is very possible to move HTML around using jQuery.

    I suggest adding some JS that runs in the footer that simply uses the .before() and .after() functions in jQuery to move the ‘acf-field’ elements around.

    Hope that helps.

  • @kristincodeswp Thanks for the nudge in the right direction. The admin only fields will work perfectly for my requirement.

  • @cloud9 hey, sorry to drag this one up, but ive just had a similar request. Did you manage to get a solution?

  • John, thank you for taking the time to help, it is really appreciated.
    I was getting errors with your code, but it prompted me to take another look at something i had been trying using get_field() instead.

    This is what i have now, which is working

    function acf_load_opposition_player_choices( $field ) {
    
    	// reset choices
    	$field['choices'] = array();
    
    	$rows = get_field( 'opposition_squad' );
    
    	//echo '<pre>';
    	//print_r( $rows );
    	//echo '</pre>';
    
    	// if has rows
    	if ( $rows ) {
    		$i = 1;
    		foreach ( $rows as $row ) {
    
    			//echo $row['opposition_player'];
    			$value = $row['opposition_player'];
    			//echo $value;
    			if ( $i < 18 ) {
    				$field['choices'][ $value ] = $value;
    			}
    			$i++;
    		}
    	}
    	//echo '<pre>';
    	//print_r( $field );
    	//echo '</pre>';
    
    	// return the field
    	return $field;
    
    }
    
    add_filter( 'acf/load_field/name=opposition_team_event', 'acf_load_opposition_player_choices' );

    I don’t really understand why this would work over the documented method, but its working 😉

    Thanks again

  • Yes they are both associated with a custom post type post.

    I have the same setup working with another repeater and select. But this repeater contains a post object. This is reflected with the slight difference in the below code. The count in this setup just ignores the last two rows. If that is removed all rows are returned.

    function acf_load_player_choices( $field ) {
    
    	// reset choices
    	$field['choices'] = array();
    
    	// if has rows
    	if ( have_rows( 'saints_squad' ) ) {
    		$i = 1;
    		// while has rows
    		while ( have_rows( 'saints_squad' ) ) {
    
    			// instantiate row
    			the_row();
    
    			// vars
    			$value = get_sub_field( 'player' );
    			$post = $value;
    			setup_postdata( $post );
    
    			if ( $i < 18 ) {
    
    				// append to choices
    				$field['choices'][ $post->post_title ] = $post->post_title;
    			}
    
    			wp_reset_postdata();
    
    			$i++;
    		}
    	}
    
    	// return the field
    	return $field;
    }
    
    add_filter( 'acf/load_field/name=saints_team_event', 'acf_load_player_choices' );

    But this setup works.

    Is there something I’m missing in the above that would cause problems with a second one?

  • That is a top level field associated with the comment field. The field is a select

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