本文整理汇总了PHP中WP_Query::get方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::get方法的具体用法?PHP WP_Query::get怎么用?PHP WP_Query::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_cs_query
/**
* Converts the WP_Query to a Cloud_Search_Query
* @return Cloud_Search_Query
*/
public function get_cs_query()
{
$cs_query = new Cloud_Search_Query();
$cs_query->add_facet(apply_filters('lift_search_facets', array()));
$parameters = apply_filters('list_search_bq_parameters', array(sprintf("(label '%s')", $this->wp_query->get('s'))), $this);
//filter to the current blog/site
$parameters[] = new Lift_Expression_Set('and', array(new Lift_Expression_Field('site_id', lift_get_current_site_id(), false), new Lift_Expression_Field('blog_id', get_current_blog_id(), false)));
$boolean_query = sprintf('(and %s)', trim(implode(' ', $parameters)));
$cs_query->set_boolean_query($boolean_query);
// size
$posts_per_page = $this->wp_query->get('posts_per_page');
if ($posts_per_page < 0) {
$posts_per_page = 9999999;
}
$cs_query->set_size($posts_per_page);
// start
$paged = $this->wp_query->get('paged');
$start = 0;
if ($paged > 1) {
$start = $posts_per_page * ($paged - 1);
}
$cs_query->set_start($start);
$orderby_values = array('date' => 'post_date_gmt', 'relevancy' => 'text_relevance');
// rank
$order = $this->wp_query->get('order');
$orderby = isset($orderby_values[$this->wp_query->get('orderby')]) ? $orderby_values[$this->wp_query->get('orderby')] : $orderby_values['relevancy'];
if ($orderby) {
$cs_query->add_rank($orderby, $order);
}
// return fields
$cs_query->add_return_field('id');
do_action_ref_array('get_cs_query', array($cs_query));
return $cs_query;
}
示例2:
/**
* @ticket 16471
*/
function test_default_query_var()
{
$query = new WP_Query();
$this->assertEquals('', $query->get('nonexistent'));
$this->assertFalse($query->get('nonexistent', false));
$this->assertTrue($query->get('nonexistent', true));
}
示例3: parse_query
/**
* Hook into the query parsing to detect oEmbed requests.
*
* If an oEmbed request is made, trigger the output.
*
* @since 4.4.0
*
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
*/
public function parse_query($wp_query)
{
if (false === $wp_query->get('oembed', false)) {
return;
}
if (false === $wp_query->get('url', false)) {
status_header(400);
echo 'URL parameter missing';
exit;
}
$url = esc_url_raw(get_query_var('url'));
$format = wp_oembed_ensure_format(get_query_var('format'));
/**
* Filter the maxwidth oEmbed parameter.
*
* @since 4.4.0
*
* @param int $maxwidth Maximum allowed width. Default 600.
*/
$maxwidth = apply_filters('oembed_default_width', 600);
$maxwidth = absint(get_query_var('maxwidth', $maxwidth));
$callback = get_query_var('_jsonp', false);
$request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback);
echo $this->dispatch($request);
exit;
}
示例4: parse_query
/**
* Hook into the query parsing to detect oEmbed requests.
*
* If an oEmbed request is made, trigger the output.
*
* @codeCoverageIgnore
*
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
*/
public function parse_query($wp_query)
{
// Check for required params.
if (false === $wp_query->get('oembed', false)) {
return;
}
if (false === $wp_query->get('url', false)) {
status_header(400);
echo 'URL parameter missing';
exit;
}
/**
* Check for the allowed query vars and set defaults.
*
* @see WP_REST_oEmbed_Controller::register_routes()
*/
$url = esc_url_raw(get_query_var('url'));
$format = sanitize_text_field(get_query_var('format', 'json'));
/**
* Filter the maxwidth oEmbed parameter.
*
* @param int $maxwidth Maximum allowed width. Defaults to 600.
*
* @return int
*/
$maxwidth = apply_filters('oembed_default_width', 600);
$maxwidth = get_query_var('maxwidth', $maxwidth);
$callback = get_query_var('_jsonp', false);
$request = array('url' => $url, 'format' => $format, 'maxwidth' => $maxwidth, 'callback' => $callback);
echo $this->dispatch($request);
exit;
}
示例5: parse_query
/**
* Set any query flags
*
* @param WP_Query $query
*
* @return void
**/
public static function parse_query($query)
{
// set paged
if ($query->is_main_query() && isset($_GET['tribe_paged'])) {
$query->set('paged', $_REQUEST['tribe_paged']);
}
// Add tribe events post type to tag queries
if ($query->is_tag && (array) $query->get('post_type') != array(TribeEvents::POSTTYPE)) {
$types = $query->get('post_type');
if (empty($types)) {
$types = array('post');
}
if (is_array($types)) {
$types[] = TribeEvents::POSTTYPE;
} else {
if (is_string($types)) {
$types = array($types, TribeEvents::POSTTYPE);
} else {
if ($types != 'any') {
$types = array('post', TribeEvents::POSTTYPE);
}
}
}
$query->set('post_type', $types);
}
$types = !empty($query->query_vars['post_type']) ? (array) $query->query_vars['post_type'] : array();
// check if any possiblity of this being an event query
$query->tribe_is_event = in_array(TribeEvents::POSTTYPE, $types) && count($types) < 2 ? true : false;
$query->tribe_is_multi_posttype = in_array(TribeEvents::POSTTYPE, $types) && count($types) >= 2 || in_array('any', $types) ? true : false;
if ('default' === $query->get('eventDisplay')) {
$query->set('eventDisplay', TribeEvents::instance()->default_view());
}
// check if any possiblity of this being an event category
$query->tribe_is_event_category = !empty($query->query_vars[TribeEvents::TAXONOMY]) ? true : false;
$query->tribe_is_event_venue = in_array(TribeEvents::VENUE_POST_TYPE, $types) ? true : false;
$query->tribe_is_event_organizer = in_array(TribeEvents::ORGANIZER_POST_TYPE, $types) ? true : false;
$query->tribe_is_event_query = $query->tribe_is_event || $query->tribe_is_event_category || $query->tribe_is_event_venue || $query->tribe_is_event_organizer ? true : false;
// move along, this is not the query you are looking for
// is the query pulling posts from the past
if ($query->is_main_query() && !empty($_REQUEST['tribe_event_display']) && $_REQUEST['tribe_event_display'] == 'past') {
$query->tribe_is_past = true;
} elseif (tribe_is_ajax_view_request() && $query->get('eventDisplay') == 'past') {
$query->tribe_is_past = true;
} else {
$query->tribe_is_past = isset($query->tribe_is_past) ? $query->tribe_is_past : false;
}
// never allow 404 on month view
if ($query->is_main_query() && $query->get('eventDisplay') == 'month' && !$query->is_tax && !$query->tribe_is_event_category) {
$query->is_post_type_archive = true;
$query->queried_object = get_post_type_object(TribeEvents::POSTTYPE);
$query->queried_object_id = 0;
}
// check if is_event_query === true and hook filter
if ($query->tribe_is_event_query) {
// fixing is_home param
$query->is_home = !empty($query->query_vars['is_home']) ? $query->query_vars['is_home'] : false;
do_action('tribe_events_parse_query', $query);
}
}
示例6: array
function test_filter_stopwords() {
$terms = 'This is a search term';
add_filter( 'wp_search_stopwords', array( $this, 'filter_wp_search_stopwords' ) );
$query = new WP_Query( array( 's' => $terms ) );
remove_filter( 'wp_search_stopwords', array( $this, 'filter_wp_search_stopwords' ) );
$this->assertNotEquals( array( 'search', 'term' ), $query->get( 'search_terms' ) );
$this->assertEquals( array( 'This', 'is', 'search', 'term' ), $query->get( 'search_terms' ) );
}
示例7: pre_get_posts
public function pre_get_posts(\WP_Query $q)
{
if ($q->get('combined_query')) {
$defaults = ['union' => 'UNION', 'args' => []];
$this->combined_query = wp_parse_args($q->get('combined_query'), $defaults);
// Setup SQL generation:
add_filter('posts_request', [$this, 'posts_request'], PHP_INT_MAX, 2);
// Get the orderby part:
add_filter('posts_orderby', [$this, 'posts_orderby'], PHP_INT_MAX);
}
}
示例8: cq_pre_get_posts
/**
* pre_get_posts callback
*
* @since 1.0.0
* @param \WP_Query $q
* @return void
*/
public function cq_pre_get_posts(\WP_Query $q)
{
// If posts_per_page is -1, then there's no limit set,
// but we do need a limit to be able to keep the order of UNION sub-queries:
// @see http://stackoverflow.com/a/7587423/2078474
if ($q->get('posts_per_page') && '-1' == $q->get('posts_per_page')) {
$q->set('posts_per_page', 999999);
}
// Remove SQL_CALC_FOUND_ROWS from the SQL query:
$q->set('no_found_rows', 1);
}
示例9: showPageContent
public static function showPageContent($content)
{
foreach (self::$_pages as $page) {
if (self::$query->get($page['query_var']) == 1) {
if (!empty(self::$_errors)) {
$viewParams = call_user_func(array('CMA_ErrorController', 'errorAction'));
ob_start();
echo self::_loadView('error', $viewParams);
$content = ob_get_clean();
} else {
$viewParams = array();
if (!empty($page['contentCallback'])) {
$viewParams = call_user_func($page['contentCallback']);
}
ob_start();
do_action('cma_flash_messages');
$viewParams['checkPermissions'] = true;
echo self::_loadView($page['viewPath'], $viewParams);
$content = ob_get_clean();
}
break;
}
}
return $content;
}
示例10: w4dev_custom_loop_shortcode
function w4dev_custom_loop_shortcode($atts)
{
static $w4dev_custom_loop;
if (!isset($w4dev_custom_loop)) {
$w4dev_custom_loop = 1;
} else {
$w4dev_custom_loop++;
}
$atts = shortcode_atts(array('paging' => 'pg' . $w4dev_custom_loop, 'post_type' => 'post', 'posts_per_page' => '5', 'post_status' => 'publish'), $atts);
$paging = $atts['paging'];
unset($atts['paging']);
if (isset($_GET[$paging])) {
$atts['paged'] = $_GET[$paging];
} else {
$atts['paged'] = 1;
}
$html = '';
$custom_query = new WP_Query($atts);
if ($custom_query->have_posts()) {
$html .= '<ul>';
while ($custom_query->have_posts()) {
$custom_query->the_post();
$html .= sprintf('<li><a href="%1$s">%2$s</a></li>', get_permalink(), get_the_title());
}
$html .= '</ul>';
}
$pagination_base = add_query_arg($paging, '%#%');
$html .= paginate_links(array('type' => '', 'base' => $pagination_base, 'format' => '?' . $paging . '=%#%', 'current' => max(1, $custom_query->get('paged')), 'total' => $custom_query->max_num_pages));
return $html;
}
示例11: media_list_table_query
/**
* Media List:
* Do the same as ^^ but for the list view.
*
* @param WP_Query $query
*
* @return array
*/
public function media_list_table_query($query)
{
if (is_admin() && $query->is_main_query() && 'upload' === get_current_screen()->id) {
$meta_query = $this->add_status_check_to_meta_query($query->get('meta_query'));
$query->set('meta_query', $meta_query);
}
}
示例12: get_posts
public function get_posts()
{
$query = $_POST['query'];
$hash = $this->get_query_hash($query);
check_ajax_referer($hash);
// $query is signed by nonce
$wp_query = new \WP_Query($query);
$posts = $wp_query->posts;
if (!$posts) {
exit('-1');
}
$posted_opts = $_POST['opts'];
$opts = array('hide_title' => $this->_bool($posted_opts['hide_title']), 'link' => in_array($posted_opts['link'], array('post', 'file', 'thickbox', 'none')) ? $posted_opts['link'] : wp_tiles()->options->get_option('link'), 'byline_template' => wp_kses_post($posted_opts['byline_template']), 'byline_template_textonly' => $this->_bool($posted_opts['byline_template_textonly']), 'images_only' => $this->_bool($posted_opts['images_only']), 'image_size' => $posted_opts['image_size'], 'text_only' => $this->_bool($posted_opts['text_only']), 'link_new_window' => $this->_bool($posted_opts['link_new_window']));
ob_start();
wp_tiles()->render_tile_html($posts, $opts);
$html = ob_get_contents();
ob_end_clean();
$ret = array('tiles' => $html);
$max_page = $wp_query->max_num_pages;
$next_page = intval($wp_query->get('paged')) + 1;
// Is there another page?
if ($next_page <= $max_page) {
$ret['has_more'] = true;
$query['paged'] = $next_page;
$ret['_ajax_nonce'] = $this->get_query_nonce($query);
} else {
$ret['has_more'] = false;
}
$this->_return($ret);
}
示例13: ep_admin_integrate
/**
* Integrate EP into proper queries
*
* @param WP_Query $query
* @since 2.1
*/
function ep_admin_integrate($query)
{
// Lets make sure this doesn't interfere with the CLI
if (defined('WP_CLI') && WP_CLI) {
return;
}
if (!$query->is_main_query()) {
return;
}
/**
* We limit to these post types to not conflict with other modules like WooCommerce
*
* @since 2.1
* @var array
*/
$post_types = array('post' => 'post', 'page' => 'page');
$supported_post_types = apply_filters('ep_admin_supported_post_types', $post_types);
$post_type = $query->get('post_type');
if (empty($post_type)) {
$post_type = 'post';
}
if (is_array($post_type)) {
foreach ($post_type as $pt) {
if (empty($supported_post_types[$pt])) {
return;
}
}
$query->set('ep_integrate', true);
} else {
if (!empty($supported_post_types[$post_type])) {
$query->set('ep_integrate', true);
}
}
}
示例14:
/**
* @param WP_Query $query
*/
function _order_posts($query)
{
if ($query->get('post_type') == 'jcaca-course' && is_admin()) {
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
$query->set('meta_key', '_rbm_course_code');
}
}
示例15: __construct
/**
* This is expected to be called in the context of the tribe_events_pre_get_posts
* action and only when it has already been determined that the request is to see
* all events making up a recurring sequence.
*
* @see Tribe__Events__Pro__Main::pre_get_posts()
*
* @param WP_Query $query
*/
public function __construct(WP_Query $query)
{
$this->query = $query;
$this->slug = $query->get('name');
if (!empty($this->slug)) {
$this->setup();
}
}