A- A+


This filter run when a post is updating. You can run it for validating the form fields. It will return error depend on your function.

Accepts 1 parameter:

$error - string


function wpuf_unique_product_sku_notice( $error ) {
    if ( isset( $_POST['_sku'] ) ) {
        global $wpdb;
        $sku = $_POST['_sku'];

        $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
        if ( $product_id ) {
            return __( 'SKU is not unique, you must enter unique SKU' );

    return '';

add_filter( 'wpuf_update_post_validate', 'wpuf_unique_product_sku_notice' );

When the form is submitted, above code will validate _sku meta value, if the same meta value found in the database then it will return an error.

When add a new post, use wpuf_add_post_validate filter to validate the form fields.