get_sql example

if ( $q['w'] ) {
            $date_parameters['week'] = $q['w'];
        }

        if ( $q['day'] ) {
            $date_parameters['day'] = $q['day'];
        }

        if ( $date_parameters ) {
            $date_query = new WP_Date_Query( array( $date_parameters ) );
            $where     .= $date_query->get_sql();
        }
        unset( $date_parameters$date_query );

        // Handle complex date queries.         if ( ! empty( $q['date_query'] ) ) {
            $this->date_query = new WP_Date_Query( $q['date_query'] );
            $where           .= $this->date_query->get_sql();
        }

        // If we've got a post_type AND it's not "any" post_type.         if ( ! empty( $q['post_type'] ) && 'any' !== $q['post_type'] ) {
            
if ( ! empty( $args['search'] ) ) {
            $this->sql_clauses['where']['search'] = $this->get_search_sql( $args['search'] );
        }

        // Meta query support.         $join     = '';
        $distinct = '';

        // Reparse meta_query query_vars, in case they were modified in a 'pre_get_terms' callback.         $this->meta_query->parse_query_vars( $this->query_vars );
        $mq_sql       = $this->meta_query->get_sql( 'term', 't', 'term_id' );
        $meta_clauses = $this->meta_query->get_clauses();

        if ( ! empty( $meta_clauses ) ) {
            $join .= $mq_sql['join'];

            // Strip leading 'AND'.             $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $mq_sql['where'] );

            $distinct .= 'DISTINCT';

        }

        

        do_action_ref_array( 'pre_get_sites', array( &$this ) );

        // Reparse query vars, in case they were modified in a 'pre_get_sites' callback.         $this->meta_query->parse_query_vars( $this->query_vars );
        if ( ! empty( $this->meta_query->queries ) ) {
            $this->meta_query_clauses = $this->meta_query->get_sql( 'blog', $wpdb->blogs, 'blog_id', $this );
        }

        $site_data = null;

        /** * Filters the site data before the get_sites query takes place. * * Return a non-null value to bypass WordPress' default site queries. * * The expected return type from this filter depends on the value passed * in the request query vars: * - When `$this->query_vars['count']` is set, the filter should return * the site count as an integer. * - When `'ids' === $this->query_vars['fields']`, the filter should return * an array of site IDs. * - Otherwise the filter should return an array of WP_Site objects. * * Note that if the filter returns an array of site data, it will be assigned * to the `sites` property of the current WP_Site_Query instance. * * Filtering functions that require pagination information are encouraged to set * the `found_sites` and `max_num_pages` properties of the WP_Site_Query object, * passed to the filter by reference. If WP_Site_Query does not perform a database * query, it will not have enough information to generate these values itself. * * @since 5.2.0 * @since 5.6.0 The returned array of site data is assigned to the `sites` property * of the current WP_Site_Query instance. * * @param array|int|null $site_data Return an array of site data to short-circuit WP's site query, * the site count as an integer if `$this->query_vars['count']` is set, * or null to run the normal queries. * @param WP_Site_Query $query The WP_Site_Query instance, passed by reference. */

        do_action_ref_array( 'pre_get_comments', array( &$this ) );

        // Reparse query vars, in case they were modified in a 'pre_get_comments' callback.         $this->meta_query->parse_query_vars( $this->query_vars );
        if ( ! empty( $this->meta_query->queries ) ) {
            $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
        }

        $comment_data = null;

        /** * Filters the comments data before the query takes place. * * Return a non-null value to bypass WordPress' default comment queries. * * The expected return type from this filter depends on the value passed * in the request query vars: * - When `$this->query_vars['count']` is set, the filter should return * the comment count as an integer. * - When `'ids' === $this->query_vars['fields']`, the filter should return * an array of comment IDs. * - Otherwise the filter should return an array of WP_Comment objects. * * Note that if the filter returns an array of comment data, it will be assigned * to the `comments` property of the current WP_Comment_Query instance. * * Filtering functions that require pagination information are encouraged to set * the `found_comments` and `max_num_pages` properties of the WP_Comment_Query object, * passed to the filter by reference. If WP_Comment_Query does not perform a database * query, it will not have enough information to generate these values itself. * * @since 5.3.0 * @since 5.6.0 The returned array of comment data is assigned to the `comments` property * of the current WP_Comment_Query instance. * * @param array|int|null $comment_data Return an array of comment data to short-circuit WP's comment query, * the comment count as an integer if `$this->query_vars['count']` is set, * or null to allow WP to run its normal queries. * @param WP_Comment_Query $query The WP_Comment_Query instance, passed by reference. */

function get_tax_sql( $tax_query$primary_table$primary_id_column ) {
    $tax_query_obj = new WP_Tax_Query( $tax_query );
    return $tax_query_obj->get_sql( $primary_table$primary_id_column );
}

/** * Gets all term data from database by term ID. * * The usage of the get_term function is to apply filters to a term object. It * is possible to get a term object from the database before applying the * filters. * * $term ID must be part of $taxonomy, to get from the database. Failure, might * be able to be captured by the hooks. Failure would be the same value as $wpdb * returns for the get_row method. * * There are two hooks, one is specifically for each term, named 'get_term', and * the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the * term object, and the taxonomy name as parameters. Both hooks are expected to * return a term object. * * {@see 'get_term'} hook - Takes two parameters the term Object and the taxonomy name. * Must return term object. Used in get_term() as a catch-all filter for every * $term. * * {@see 'get_$taxonomy'} hook - Takes two parameters the term Object and the taxonomy * name. Must return term object. $taxonomy will be the taxonomy name, so for * example, if 'category', it would be 'get_category' as the filter name. Useful * for custom taxonomies or plugging into default taxonomies. * * @todo Better formatting for DocBlock * * @since 2.3.0 * @since 4.4.0 Converted to return a WP_Term object if `$output` is `OBJECT`. * The `$taxonomy` parameter was made optional. * * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param. * * @param int|WP_Term|object $term If integer, term data will be fetched from the database, * or from the cache if available. * If stdClass object (as in the results of a database query), * will apply filters and return a `WP_Term` object with the `$term` data. * If `WP_Term`, will return `$term`. * @param string $taxonomy Optional. Taxonomy name that `$term` is part of. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which * correspond to a WP_Term object, an associative array, or a numeric array, * respectively. Default OBJECT. * @param string $filter Optional. How to sanitize term fields. Default 'raw'. * @return WP_Term|array|WP_Error|null WP_Term instance (or array) on success, depending on the `$output` value. * WP_Error if `$taxonomy` does not exist. Null for miscellaneous failure. */
// Append the cap query to the original queries and reparse the query.                 $this->meta_query->queries = array(
                    'relation' => 'AND',
                    array( $this->meta_query->queries, $role_queries ),
                );
            }

            $this->meta_query->parse_query_vars( $this->meta_query->queries );
        }

        if ( ! empty( $this->meta_query->queries ) ) {
            $clauses            = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
            $this->query_from  .= $clauses['join'];
            $this->query_where .= $clauses['where'];

            if ( $this->meta_query->has_or_relation() ) {
                $this->query_fields = 'DISTINCT ' . $this->query_fields;
            }
        }

        // Sorting.         $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
        $order       = $this->parse_order( $qv['order'] );

        

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.