1. Home
  2. WP User Frontend Pro
  3. Developer Docs
  4. Filters
  5. wpuf_update_post_validate

wpuf_update_post_validate

Parameters

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

Example

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.

Was this article helpful to you? Yes No

How can we help?