Skip to content

Instantly share code, notes, and snippets.

@anag0
Created Jul 18, 2016
Embed
What would you like to do?
ASP_Query defaults
<?php
$args = array(
// ----------------------------------------------------------------
// 1. GENERIC arguments
// ----------------------------------------------------------------
's' => '', // search query
/**
* @param string|array search_type
* cpt -> posts, pages, custom post types
* taxonomies -> tags, categories and taxonomy terms based on taxonomy slug
* users -> users
* blogs -> multisite blog titles
* buddypress -> buddypress groups or activities
* comments -> comment results
* attachments -> file attachments
*/
'search_type' => 'cpt',
'engine' => 'regular', // regular|index -> index only used on cpt
'posts_per_page' => 10, // posts per page, for non ajax requests only
'page' => 1, // which page of results, starts from 1
'keyword_logic' => "OR", // OR|AND|OREX|ANDEX
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// 2. POST and CUSTOM POST TYPE related arguments
// ----------------------------------------------------------------
'post_type' => array('post', 'page'), // post types to look for
'post_status' => array('publish'), // post statuses
'post_fields' => array( // post fields to search within
'title', 'content', 'excerpt', 'terms'
),
'post_custom_fields' => array(), // search within custom fields
'post_in' => array(), // string|array -> limit potential results pool to array of IDs
'post_not_in' => array(), // string|array -> explicity exclude IDs from search results
'post_tax_filter' => array( // taxonomy filter support
/*
array(
'taxonomy' => 'category', // taxonomy name
'include' => array(1, 2, 3, 4), // array of taxonomy term IDs to include
'exclude' => array(5, 6, 7, 8) // array of taxonomy term IDs to exclude
)
*/
),
'post_meta_filter' => array( // meta_query support
/*
array(
'key' => 'age', // meta key
'value' => array( 3, 4 ), // mixed|array
// @param string|array compare
// Numeric Operators
// '<' -> less than
// '>' -> more than
// '<>' -> not equals
// '=' -> equals
// 'BETWEEN' -> between two values
// String Operators
// 'LIKE'
// 'NOT LIKE'
//
'operator' => 'BETWEEN'
)
*/
),
'post_date_filter' => array( // date_query support
/*
array(
'year' => 2015, // year, month, day ...
'month' => 6,
'day' => 1,
'date' => "2015-06-01", // .. or date parameter in y-m-d format
'operator' => 'include', // include|exclude
'interval' => 'before' // before|after
)
*/
),
'post_user_filter' => array(
/*
'include' => (1, 2, 3, 4), // include by IDs
'exclude' => (5, 6, 7, 8) // exclude by IDs
*/
),
'post_primary_order' => "relevance DESC",
'post_secondary_order' => "post_date DESC",
// ADVANCED
'_post_get_content' => false,
'_post_get_excerpt' => false,
'_post_allow_empty_tax_term' => false,
'_post_use_relevance' => true,
// Special post tag filtering
'_post_tags_active' => false,
'_post_tags_include' => array(),
'_post_tags_exclude' => array(),
'_post_tags_logic' => "OR",
'_post_tags_empty' => 0,
'_post_meta_logic' => "AND",
'_post_meta_allow_null' => 0,
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// 3. ATTACHMENT search related arguments
// ----------------------------------------------------------------
'attachments_search_title' => true,
'attachments_search_content' => true,
'attachments_search_caption' => true,
'attachments_search_terms' => false,
'attachment_use_image' => true,
'attachment_mime_types' => array('image/jpeg', 'image/gif', 'image/png', 'image/tiff', 'image/x-icon'),
'attachment_exclude' => array(), // array of IDs
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// 4. BUDDYPRESS related arguments
'bp_groups_search' => false,
'bp_groups_search_public' => true,
'bp_groups_search_private' => true,
'bp_groups_search_hidden' => true,
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// 5. COMMENTS related arguments
// Nothing here yet..
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// 6. TAXONOMY TERM search related arguments
// ----------------------------------------------------------------
'taxonomy_include' => array("category", "post_tag"), // taxonomies to search for terms
'taxonomy_terms_exclude' => array(), // terms to exclude by ID
'taxonomy_terms_search_description' => true,
// ADVANCED
'_taxonomy_posts_affected' => true,
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// 7. USER SEARCH
// ----------------------------------------------------------------
'user_login_search' => true,
'user_display_name_search' => true,
'user_first_name_search' => true,
'user_last_name_search' => true,
'user_bio_search' => true,
'user_search_meta_fields' => array(),
'user_search_bp_fields' => array(),
'user_search_exclude_roles' => array(),
// ----------------------------------------------------------------
/**
* OTHER ADVANCED ATTRIBUTES
*
* Don't use/override these, unless you know what you are doing.
*/
'_id' => -1,
'_o' => false,
// LIMITS
'limit' => 0, // overall results limit, if <0, then evenly distributed between sources
'_limit' => 0, // calculated limit based on the previous limit parameter
/**
* _call_num ->
* Number of the consecutive ajax requests with the same configuration triggered by
* clicking on the 'More results..' link
* This is required to calculate the correct start of the result slicing
*/
'_call_num' => 0,
'posts_limit' => 10,
'posts_limit_override' => 50,
'taxonomies_limit' => 10,
'taxonomies_limit_override' => 20,
'users_limit' => 10,
'users_limit_override' => 20,
'blogs_limit' => 10,
'blogs_limit_override' => 20,
'buddypress_limit' => 10,
'buddypress_limit_override' => 20,
'comments_limit' => 10,
'comments_limit_override' => 20,
'attachments_limit' => 10,
'attachments_limit_override' => 20,
'_charcount' => 0,
'_exact_matches' => false,
'_qtranslate_lang' => "en", // qtranslatex language data
'_wpml_lang' => "", // WPML language
'_exclude_page_parent_child' => "", // parent page exclusion data (comma separated list)
'_taxonomy_group_logic' => 'AND',
'_db_force_case' => 'none',
'_db_force_utf8_like' => 0,
'_db_force_unicode' => 0,
'_ajax_search' => false // Needs to be set explicitly to TRUE in search Ajax Handler class
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment