sanitize_post_field example

function get_post_field( $field$post = null, $context = 'display' ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return '';
    }

    if ( ! isset( $post->$field ) ) {
        return '';
    }

    return sanitize_post_field( $field$post->$field$post->ID, $context );
}

/** * Retrieves the mime type of an attachment based on the ID. * * This function can be used with any post type, but it makes more sense with * attachments. * * @since 2.0.0 * * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post. * @return string|false The mime type on success, false on failure. */
return wp_list_pluck( $terms, 'name' );
        }

        // Rest of the values need filtering.         if ( 'ancestors' === $key ) {
            $value = get_post_ancestors( $this );
        } else {
            $value = get_post_meta( $this->ID, $key, true );
        }

        if ( $this->filter ) {
            $value = sanitize_post_field( $key$value$this->ID, $this->filter );
        }

        return $value;
    }

    /** * {@Missing Summary} * * @since 3.5.0 * * @param string $filter Filter. * @return WP_Post */

function post_exists( $title$content = '', $date = '', $type = '', $status = '' ) {
    global $wpdb;

    $post_title   = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
    $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
    $post_date    = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
    $post_type    = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
    $post_status  = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) );

    $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
    $args  = array();

    if ( ! empty( $date ) ) {
        $query .= ' AND post_date = %s';
        $args[] = $post_date;
    }
Home | Imprint | This part of the site doesn't use cookies.