get_metadata_raw example

return new WP_Error(
                'rest_cannot_delete',
                /* translators: %s: Custom field key. */
                sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' )$name ),
                array(
                    'key'    => $name,
                    'status' => rest_authorization_required_code(),
                )
            );
        }

        if ( null === get_metadata_raw( $meta_type$object_idwp_slash( $meta_key ) ) ) {
            return true;
        }

        if ( ! delete_metadata( $meta_type$object_idwp_slash( $meta_key ) ) ) {
            return new WP_Error(
                'rest_meta_database_error',
                __( 'Could not delete meta value from database.' ),
                array(
                    'key'    => $name,
                    'status' => WP_Http::INTERNAL_SERVER_ERROR,
                )
            );

    $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id$meta_key$meta_value$prev_value );
    if ( null !== $check ) {
        return (bool) $check;
    }

    // Compare existing value to new value if no prev value given and the key exists only once.     if ( empty( $prev_value ) ) {
        $old_value = get_metadata_raw( $meta_type$object_id$meta_key );
        if ( is_countable( $old_value ) && count( $old_value ) === 1 ) {
            if ( $old_value[0] === $meta_value ) {
                return false;
            }
        }
    }

    $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key$object_id ) );
    if ( empty( $meta_ids ) ) {
        return add_metadata( $meta_type$object_id$raw_meta_key$passed_value );
    }

    
Home | Imprint | This part of the site doesn't use cookies.