asp_query_{type}

Gives access to the query string, before executing.

Gives access to the specific type of search query string, before executing.

Types

  • asp_query_cpt

  • asp_query_indextable

  • asp_query_attachments

  • asp_query_terms

  • asp_query_users

  • asp_query_comments

// Regular engine post type search query
apply_filters('asp_query_cpt', string $query, array $args, int $search_id, bool $is_ajax);
// Index table post type engine search query
apply_filters('asp_query_indextable', string $query, array $args, int $search_id, bool $is_ajax);
// Attachment search query
apply_filters('asp_query_attachments', string $query, array $args, int $search_id, bool $is_ajax);
// Taxonomy term search query
apply_filters('asp_query_terms', string $query, array $args, int $search_id, bool $is_ajax);
// User search query
apply_filters('asp_query_users', string $query, array $args, int $search_id, bool $is_ajax);
// Comments search query
apply_filters('asp_query_comments', string $query, array $args, int $search_id, bool $is_ajax);

Parameters

  • $query (string) - SQL query string

  • $args (array) - Search arguments

  • $search_id (int) - Search instance ID

  • $is_ajax (bool) - Is the current request an ajax search

Always be careful when making direct changes to a query, as it is directly sent to the database server for execution.

Usage

add_filter( 'asp_query_cpt', 'asp_modify_query_string', 10, 4 );
function asp_modify_query_string( $query, $args, $search_id, $is_ajax ) {
$query = str_replace('wp_postmeta', 'wp_my_postmeta', $query);
return $query;
}