Support

Account

Home Forums ACF PRO Programmatic Location Rules Reply To: Programmatic Location Rules

  • Hey John!

    Thanks for pointing me in the right direction, this is what’ I’m using and it seems to accomplish what I need.

    add_filter('acf/get_field_group', 'my_change_field_group');
    function my_change_field_group($group) {
    
    	$get_current_screen = get_current_screen();
    	$get_current_post_type = $get_current_screen->post_type;
    	$my_option = get_field('my-option','option');
    
    	if (
    		$get_current_post_type == 'my-cpt' &&
    		$my_option == 'stuff' &&
    		$group['key'] == 'group_123456789'
    	) {
    		$group['location'] = array(
    			array(
    				array(
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'my-cpt',
    				),
    			),
    		);
    	}
    	return $group;
    };