get_search_sql example

/** * Make private/protected methods readable for backward compatibility. * * @since 4.0.0 * * @param string $name Method to call. * @param array $arguments Arguments to pass when calling. * @return mixed|false Return value of the callback, false otherwise. */
    public function __call( $name$arguments ) {
        if ( 'get_search_sql' === $name ) {
            return $this->get_search_sql( ...$arguments );
        }
        return false;
    }

    /** * Constructor. * * Sets up the comment query, based on the query vars passed. * * @since 4.2.0 * @since 4.4.0 `$parent__in` and `$parent__not_in` were added. * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`, * `$hierarchical`, and `$update_comment_post_cache` were added. * @since 4.5.0 Introduced the `$author_url` argument. * @since 4.6.0 Introduced the `$cache_domain` argument. * @since 4.9.0 Introduced the `$paged` argument. * @since 5.1.0 Introduced the `$meta_compare_key` argument. * @since 5.3.0 Introduced the `$meta_type_key` argument. * * @param string|array $query { * Optional. Array or query string of comment query parameters. Default empty. * * @type string $author_email Comment author email address. Default empty. * @type string $author_url Comment author URL. Default empty. * @type int[] $author__in Array of author IDs to include comments for. Default empty. * @type int[] $author__not_in Array of author IDs to exclude comments for. Default empty. * @type int[] $comment__in Array of comment IDs to include. Default empty. * @type int[] $comment__not_in Array of comment IDs to exclude. Default empty. * @type bool $count Whether to return a comment count (true) or array of * comment objects (false). Default false. * @type array $date_query Date query clauses to limit comments by. See WP_Date_Query. * Default null. * @type string $fields Comment fields to return. Accepts 'ids' for comment IDs * only or empty for all fields. Default empty. * @type array $include_unapproved Array of IDs or email addresses of users whose unapproved * comments will be returned by the query regardless of * `$status`. Default empty. * @type int $karma Karma score to retrieve matching comments for. * Default empty. * @type string|string[] $meta_key Meta key or keys to filter by. * @type string|string[] $meta_value Meta value or values to filter by. * @type string $meta_compare MySQL operator used for comparing the meta value. * See WP_Meta_Query::__construct() for accepted values and default value. * @type string $meta_compare_key MySQL operator used for comparing the meta key. * See WP_Meta_Query::__construct() for accepted values and default value. * @type string $meta_type MySQL data type that the meta_value column will be CAST to for comparisons. * See WP_Meta_Query::__construct() for accepted values and default value. * @type string $meta_type_key MySQL data type that the meta_key column will be CAST to for comparisons. * See WP_Meta_Query::__construct() for accepted values and default value. * @type array $meta_query An associative array of WP_Meta_Query arguments. * See WP_Meta_Query::__construct() for accepted values. * @type int $number Maximum number of comments to retrieve. * Default empty (no limit). * @type int $paged When used with `$number`, defines the page of results to return. * When used with `$offset`, `$offset` takes precedence. Default 1. * @type int $offset Number of comments to offset the query. Used to build * LIMIT clause. Default 0. * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. * Default: true. * @type string|array $orderby Comment status or array of statuses. To use 'meta_value' * or 'meta_value_num', `$meta_key` must also be defined. * To sort by a specific `$meta_query` clause, use that * clause's array key. Accepts: * - 'comment_agent' * - 'comment_approved' * - 'comment_author' * - 'comment_author_email' * - 'comment_author_IP' * - 'comment_author_url' * - 'comment_content' * - 'comment_date' * - 'comment_date_gmt' * - 'comment_ID' * - 'comment_karma' * - 'comment_parent' * - 'comment_post_ID' * - 'comment_type' * - 'user_id' * - 'comment__in' * - 'meta_value' * - 'meta_value_num' * - The value of `$meta_key` * - The array keys of `$meta_query` * - false, an empty array, or 'none' to disable `ORDER BY` clause. * Default: 'comment_date_gmt'. * @type string $order How to order retrieved comments. Accepts 'ASC', 'DESC'. * Default: 'DESC'. * @type int $parent Parent ID of comment to retrieve children of. * Default empty. * @type int[] $parent__in Array of parent IDs of comments to retrieve children for. * Default empty. * @type int[] $parent__not_in Array of parent IDs of comments *not* to retrieve * children for. Default empty. * @type int[] $post_author__in Array of author IDs to retrieve comments for. * Default empty. * @type int[] $post_author__not_in Array of author IDs *not* to retrieve comments for. * Default empty. * @type int $post_id Limit results to those affiliated with a given post ID. * Default 0. * @type int[] $post__in Array of post IDs to include affiliated comments for. * Default empty. * @type int[] $post__not_in Array of post IDs to exclude affiliated comments for. * Default empty. * @type int $post_author Post author ID to limit results by. Default empty. * @type string|string[] $post_status Post status or array of post statuses to retrieve * affiliated comments for. Pass 'any' to match any value. * Default empty. * @type string|string[] $post_type Post type or array of post types to retrieve affiliated * comments for. Pass 'any' to match any value. Default empty. * @type string $post_name Post name to retrieve affiliated comments for. * Default empty. * @type int $post_parent Post parent ID to retrieve affiliated comments for. * Default empty. * @type string $search Search term(s) to retrieve matching comments for. * Default empty. * @type string|array $status Comment statuses to limit results by. Accepts an array * or space/comma-separated list of 'hold' (`comment_status=0`), * 'approve' (`comment_status=1`), 'all', or a custom * comment status. Default 'all'. * @type string|string[] $type Include comments of a given type, or array of types. * Accepts 'comment', 'pings' (includes 'pingback' and * 'trackback'), or any custom type string. Default empty. * @type string[] $type__in Include comments from a given array of comment types. * Default empty. * @type string[] $type__not_in Exclude comments from a given array of comment types. * Default empty. * @type int $user_id Include comments for a specific user ID. Default empty. * @type bool|string $hierarchical Whether to include comment descendants in the results. * - 'threaded' returns a tree, with each comment's children * stored in a `children` property on the `WP_Comment` object. * - 'flat' returns a flat array of found comments plus * their children. * - Boolean `false` leaves out descendants. * The parameter is ignored (forced to `false`) when * `$fields` is 'ids' or 'counts'. Accepts 'threaded', * 'flat', or false. Default: false. * @type string $cache_domain Unique cache key to be produced when this query is stored in * an object cache. Default is 'core'. * @type bool $update_comment_meta_cache Whether to prime the metadata cache for found comments. * Default true. * @type bool $update_comment_post_cache Whether to prime the cache for comment posts. * Default false. * } */

            $search_columns = apply_filters( 'site_search_columns', $search_columns$this->query_vars['search']$this );

            $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search']$search_columns );
        }

        $date_query = $this->query_vars['date_query'];
        if ( ! empty( $date_query ) && is_array( $date_query ) ) {
            $this->date_query = new WP_Date_Query( $date_query, 'registered' );

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

        $join    = '';
        

            $search_columns = apply_filters( 'user_search_columns', $search_columns$search$this );

            $this->query_where .= $this->get_search_sql( $search$search_columns$wild );
        }

        if ( ! empty( $include ) ) {
            // Sanitized earlier.             $ids                = implode( ',', $include );
            $this->query_where .= " AND $wpdb->users.ID IN ($ids)";
        } elseif ( ! empty( $qv['exclude'] ) ) {
            $ids                = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
            $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
        }

        
        if ( is_array( $this->query_vars['path__in'] ) ) {
            $this->sql_clauses['where']['path__in'] = "$wpdb->site.path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";
        }

        // Parse network path for a NOT IN clause.         if ( is_array( $this->query_vars['path__not_in'] ) ) {
            $this->sql_clauses['where']['path__not_in'] = "$wpdb->site.path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";
        }

        // Falsey search strings are ignored.         if ( strlen( $this->query_vars['search'] ) ) {
            $this->sql_clauses['where']['search'] = $this->get_search_sql(
                $this->query_vars['search'],
                array( "$wpdb->site.domain", "$wpdb->site.path" )
            );
        }

        $join = '';

        $where = implode( ' AND ', $this->sql_clauses['where'] );

        $groupby = '';

        
        if ( $number && ! $hierarchical && ! $child_of && '' === $parent ) {
            if ( $offset ) {
                $limits = 'LIMIT ' . $offset . ',' . $number;
            } else {
                $limits = 'LIMIT ' . $number;
            }
        } else {
            $limits = '';
        }

        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();

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