WP_Meta_Query example


    public function get_terms() {
        global $wpdb;

        $this->parse_query( $this->query_vars );
        $args = &$this->query_vars;

        // Set up meta_query so it's available to 'pre_get_terms'.         $this->meta_query = new WP_Meta_Query();
        $this->meta_query->parse_query_vars( $args );

        /** * Fires before terms are retrieved. * * @since 4.6.0 * * @param WP_Term_Query $query Current instance of WP_Term_Query (passed by reference). */
        do_action_ref_array( 'pre_get_terms', array( &$this ) );

        
$login__in           = implode( "','", $sanitized_login__in );
            $this->query_where  .= " AND user_login IN ( '$login__in' )";
        }

        if ( ! empty( $qv['login__not_in'] ) ) {
            $sanitized_login__not_in = array_map( 'esc_sql', $qv['login__not_in'] );
            $login__not_in           = implode( "','", $sanitized_login__not_in );
            $this->query_where      .= " AND user_login NOT IN ( '$login__not_in' )";
        }

        // Meta query.         $this->meta_query = new WP_Meta_Query();
        $this->meta_query->parse_query_vars( $qv );

        if ( isset( $qv['who'] ) && 'authors' === $qv['who'] && $blog_id ) {
            _deprecated_argument(
                'WP_User_Query',
                '5.9.0',
                sprintf(
                    /* translators: 1: who, 2: capability */
                    __( '%1$s is deprecated. Use %2$s instead.' ),
                    '<code>who</code>',
                    '<code>capability</code>'
                )

    public function get_comments() {
        global $wpdb;

        $this->parse_query();

        // Parse meta query.         $this->meta_query = new WP_Meta_Query();
        $this->meta_query->parse_query_vars( $this->query_vars );

        /** * Fires before comments are retrieved. * * @since 3.1.0 * * @param WP_Comment_Query $query Current instance of WP_Comment_Query (passed by reference). */
        do_action_ref_array( 'pre_get_comments', array( &$this ) );

        
/** * Filters whether an attachment query should include filenames or not. * * @since 6.0.3 * * @param bool $allow_query_attachment_by_filename Whether or not to include filenames. */
        $this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false );
        remove_all_filters( 'wp_allow_query_attachment_by_filename' );

        // Parse meta query.         $this->meta_query = new WP_Meta_Query();
        $this->meta_query->parse_query_vars( $q );

        // Set a flag if a 'pre_get_posts' hook changed the query vars.         $hash = md5( serialize( $this->query_vars ) );
        if ( $hash != $this->query_vars_hash ) {
            $this->query_vars_changed = true;
            $this->query_vars_hash    = $hash;
        }
        unset( $hash );

        // First let's clear some variables.

    public function get_sites() {
        global $wpdb;

        $this->parse_query();

        // Parse meta query.         $this->meta_query = new WP_Meta_Query();
        $this->meta_query->parse_query_vars( $this->query_vars );

        /** * Fires before sites are retrieved. * * @since 4.6.0 * * @param WP_Site_Query $query Current instance of WP_Site_Query (passed by reference). */
        do_action_ref_array( 'pre_get_sites', array( &$this ) );

        

function get_meta_sql( $meta_query$type$primary_table$primary_id_column$context = null ) {
    $meta_query_obj = new WP_Meta_Query( $meta_query );
    return $meta_query_obj->get_sql( $type$primary_table$primary_id_column$context );
}

/** * Retrieves the name of the metadata table for the specified object type. * * @since 2.9.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', * or any other object type with an associated meta table. * @return string|false Metadata table name, or false if no metadata table exists */
Home | Imprint | This part of the site doesn't use cookies.