Support

Account

Forum Replies Created

  • Using $_GET to grab the post id worked great. Thanks so much.

    Here’s the final function:

    function toind_alter_flexible_content( $field_group ) {
    	if ( isset( $_GET['post'] ) ) {
    		$post_id   = intval( $_GET['post'] );
    		$post_type = get_post_type( $post_id );
    		if ( 'group_5c76d2e8213cf' === $field_group['key'] && 'event' === $post_type ) {
    			$field_group['menu_order'] = 7;
    			$field_group['position']   = 'normal';
    		}
    	}
    	return $field_group;
    }
    add_filter( 'acf/validate_field_group', 'toind_alter_flexible_content', 20 );
    

    Thank you again so much for all of your help.

  • The WordPress global $post is not set yet either…but…the ACF at some point knows the post type because it needs to know the post type in order to know whether or not to show the field group based on the location settings. Wondering what info I do have access to from my function?

  • Sorry to say still no luck. My function gets executed and returns the altered field_group, but no change to the order on the editing screen. It still appears that acf/settings/load_json hook is getting fired again afterward as the breakpoint I put in that hook gets hit after my function to alter the group.

    I tried testing it with the post type check removed and it worked, so I think you are right about finding a different way to check the post type. I’ll look into that and let you know what I find out. The strange thing is that the breakpoint inside the if statement gets hit, so I assumed the post_type check was working.

    Thanks again for all your help.

  • Thank you again John. I’m not quite sure how/where to use the code you mentioned above. I tried replacing the other hook with this one:

    function toind_alter_flexible_content( $field_group ) {
    	//var_dump( $GLOBALS['post_type'] );
    	if ( 'group_5c76d2e8213cf' === $field_group['key'] && 'event' == $GLOBALS['post_type'] ) {
    		$field_group['menu_order'] = 7;
    		$field_group['position']   = 'normal';
    	}
    	return $field_group;
    }
    add_filter( 'acf/validate_field_group', 'toind_alter_flexible_content' );

    Which is not what you showed above, but I don’t understand where I would put that code that you showed and how I would work my alteration into the process.
    The code above did get hit, but once again, no change in the position of the field group on the edit screen.

  • I added the var_dump and verified that it is set. It output /Users/nrackleff/Sites/toind/web/wp-content/themes/ts_toind/functions.php:356:string 'event' (length=5)

    I also added a breakpoint inside the if statement and the code is getting executed. The breakpoint does get hit when I run the code, so that doesn’t seem to be the problem.

    What is the difference between get_field_group and load_field_group? Do they both get called after the json has loaded? Just want to make sure I’m using the correct hook.

  • Hi John. Thanks for jumping in. We’re using a custom plugin to include the json save and load.

    function ts_acf_json_load( $paths ) {
    	$paths[] = trailingslashit( WP_CONTENT_DIR ) . 'acf-json';
    	return $paths;
    }
    add_filter( 'acf/settings/load_json', 'ts_acf_json_load' );

    Then, in the functions.php within the theme, we have this code to alter it for a specific post type.

    function toind_get_flexible_content( $field_group ) {
    	if ( 'group_5c76d2e8213cf' === $field_group['key'] && 'event' == $GLOBALS['post_type'] ) {
    		$field_group['menu_order'] = 7;
    		$field_group['position']   = 'normal';
    	}
    	return $field_group;
    }
    add_filter( 'acf/get_field_group', 'toind_get_flexible_content' );
Viewing 6 posts - 1 through 6 (of 6 total)