Support

Account

Home Forums General Issues Display different field groups on New and Edit Post Reply To: Display different field groups on New and Edit Post

  • I’m a little lost about why you’d want to display different field groups on new or existing posts. There would be some problems with doing this because, even if you name the fields the same, the field keys for the fields in each group will be different and could cause problems saving an retrieving values from the database.

    However, that being said, the problems are in your filter match function

    single = instead of double == and || instead of && and I altered the order the values checked in the!= section

    
    // Matching the rule
    add_filter('acf/location/rule_match/postmode', 'acf_location_rules_match_postmode', 10, 3);
    function acf_location_rules_match_postmode( $match, $rule, $options )
    {
    	global $pagenow;
    	$rule_value = $rule['value'];
    	if ($rule['operator'] == '==') {
    		if ($rule_value == 'post_new' && $pagenow == 'post-new.php') $match = true;
    		if ($rule_value == 'post_edit' && $pagenow == 'post.php' ) $match = true;
    	} elseif($rule['operator'] == '!=') {
    		if ($rule_value == 'post_edit' && $pagenow == 'post-new.php') $match = true;
    		if ($rule_value == 'post_new'  && $pagenow == 'post.php') $match = true;
    	}
    	
    	return $match;
    }