Value add to validation return problem ( Wordpress, WPUF & ACF & CPT Plugins )

function wpuf_unique_kimlik_no_uyari( $error ) {
    if ( isset( $_POST['musteri_kimlik_numarasi'] ) ) {
        global $wpdb;   
        $kimlikno = $_POST['musteri_kimlik_numarasi'];
        $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='musteri_kimlik_numarasi' AND meta_value='%s' LIMIT 1", $kimlikno ) );
        if ( $product_id ) {
            return __( 'This is an Error!' );
        }
    }
    return '';
}
add_filter( 'wpuf_add_post_validate', 'wpuf_unique_kimlik_no_uyari' );

This code is working but i can’t write an value in return.

function wpuf_unique_kimlik_no_uyari( $error ) {
    if ( isset( $_POST['musteri_kimlik_numarasi'] ) ) {
        global $wpdb;   
        $kimlikno = $_POST['musteri_kimlik_numarasi'];
        $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='musteri_kimlik_numarasi' AND meta_value='%s' LIMIT 1", 
        $kimlikno ) );
        $sonucc =  get_field('musteri_danismani', $product_id);
        $tpt = the_field('calisan_adi_soyadi', $sonucc);
        $tpt2 = the_field('calisan_sirket_numarasi', $sonucc);
        if ( $product_id ) {
            return __( $tpt ."". $tpt2 );
        }
    }
    return '';
}
add_filter( 'wpuf_add_post_validate', 'wpuf_unique_kimlik_no_uyari' );

This code doesn’t work. Please can anyone help me? How can i add a value to return ?

Please can you add a bit more information on this? In what way does it not work? Just the returning part, or somewhere else? Do you get error messages? What are they?

What’s the purpose of the two underline characters before your return value inside the if() clause? If I do that in plain-vanilla PHP test, I get a parse error.

return __( $tpt ."". $tpt2 );
        ^ here 

I don’t know the various platforms you are using, but if this line is correct:

$product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM 
$wpdb->postmeta WHERE meta_key='musteri_kimlik_numarasi' AND 
meta_value='%s' LIMIT 1", $kimlikno ) );

don’t you need the $wpdb-> before your get_field() and the_field() calls too, or are they separate functions somewhere? I’m guessing, though, without more detail on how it fails.

Hi droopsnoot,

Thanks for your reply.( Sorry for my english :slight_smile: )

Let me explain the problem. Customers, Employees and so on. I’ve created 2 different post types. (CPT UI & ACF) There is a musteri_kimlik_no and musteri_danismani field on the Customers page. musteri_danismani field pulls data from the Employees page. Employees page has fields like calisan_adi_soyadi and calisan_sirket_numarasi.

Now,
I created a form in the frontend(WP User Frontend). When customers complete this form, the data is printed in the corresponding fields on the Customers page and creates a new customer. For the fields that are unique in this form, I query whether the record exists in the system and print an error on the screen. For example: musteri_kimlik_no has to be filled in uniquely. If musteri_kimlik_no is registered in the system, I would like to withdraw the musteri_danismani field from the relevant customer page. I want to pull the data(calisan_adi_soyadi and calisan_sirket_numarasi) from the Employees page using the musteri_danismani field and print it to the error screen.

Some Information:

get_field and the_field are custom field option. These are using for getting data for custom fields with advanced custom fields plugin in wordpress. ( you can see it : https://www.advancedcustomfields.com/resources/get_field/
https://www.advancedcustomfields.com/resources/the_field/)

If you saying another way for getting data i can see it :slight_smile:

When i using this code;

function wpuf_unique_kimlik_no_uyari( $error ) {
    if ( isset( $_POST['musteri_kimlik_numarasi'] ) ) {
        global $wpdb;   
        $kimlikno = $_POST['musteri_kimlik_numarasi'];
        $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='musteri_kimlik_numarasi' AND meta_value='%s' LIMIT 1", $kimlikno ) );
        if ( $product_id ) {
            return $product_id;
        }
    }
    return '';
}
add_filter( 'wpuf_add_post_validate', 'wpuf_unique_kimlik_no_uyari' );

“return $product_id;”

The error screen shows the id of the page that contains the data entered in the musteri_kimlik_no field.
In other words, product_id is the id of the page that contains the data entered in the musteri_kimlik_no field.

And i use get_field :slight_smile: But not working :frowning: Submit form validation doesn’t work when i change return code :S