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;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.