Home › Forums › Backend Issues (wp-admin) › Check if value already exist 2 › Reply To: Check if value already exist 2
That’s exactly what I’m looking for – thanks.
But is it possible to combine two or more fields?
So if Field A has value ‘x’ and Field B value ‘y’, there must not be another combination of these two fields with these values.
My code looks like this, but it doesn’t work:
add_filter('acf/validate_value/name=strasse', 'validate_lien_video_filter', 10, 4);
function validate_lien_video_filter($valid, $value, $field, $input) {
$post_id_field_key = 'field_58ac5c77d3d6e';
if (!$valid || $value == '' || !isset($_POST['acf'][$post_id_field_key])) {
return $valid;
}
// change the field key below to the field key for your
// hide_post_id_field field
$post_id = $_POST['acf'][$post_id_field_key];
global $post;
$id = $post->ID;
$plz = get_field('plz', $id);
$location = get_field('ort', $id);
$args = array(
'post__not_in' => array($post_id), // do not check this post
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'strasse',
'value' => $value
),
array(
'key' => 'plz',
'value' => $plz
),
array(
'key' => 'ort',
'value' => $location
)
)
);
$query = new WP_Query($args);
if (count($query->posts)) {
// found at least one post that
// already has $value
$valid = 'There is already a post using this video';
}
return $valid;
}
Do you have a hint for me to solve this problem? Thank you so much! Really great support!
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.