Home › Forums › ACF PRO › Checking if Custom Post Type already Exists › Reply To: Checking if Custom Post Type already Exists
I believe you can check if a student has a certificate or not like this:
// Get the posted data
$posted_course = $_POST['acf']['field_1234567890abc'];
$student_name = $_POST['acf']['field_abcdefghij123'];
// Check if a certificate with the same name and course exsists or not
$the_posts = get_posts(array(
'post_type' => 'certificate',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'student_name_field',
'value' => $student_name
'compare' => '=',
),
array(
'key' => 'course_field',
'value' => $posted_course,
'compare' => '=',
),
),
));
if( $the_post ){
// The student has taken the course. Give a warning here
} else {
// The student hasn't taken the course yet. Process it here.
}
Where ‘field_1234567890abc’ and ‘field_abcdefghij123’ is the field keys.
I hope this helps 🙂
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.