本文整理汇总了PHP中WP_Query::parse_query方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::parse_query方法的具体用法?PHP WP_Query::parse_query怎么用?PHP WP_Query::parse_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::parse_query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpml_home_url_parse_query
/**
* @param WP_Query $q
*
* @return mixed
*/
function wpml_home_url_parse_query($q)
{
if (!$q->is_main_query()) {
return $q;
}
global $sitepress_settings;
$site_url = get_site_url();
$parts = parse_url($site_url);
if (!isset($parts['path'])) {
$parts['path'] = '';
}
if (!WPML_Root_Page::is_current_request_root()) {
return $q;
} else {
remove_action('parse_query', 'wpml_home_url_parse_query');
$request_array = explode('/', $_SERVER["REQUEST_URI"]);
$sanitized_query = array_pop($request_array);
$potential_pagination_parameter = array_pop($request_array);
if (is_numeric($potential_pagination_parameter)) {
if ($sanitized_query) {
$sanitized_query .= '&';
}
$sanitized_query .= 'page=' . $potential_pagination_parameter;
}
$sanitized_query = str_replace('?', '', $sanitized_query);
$q->parse_query($sanitized_query);
add_action('parse_query', 'wpml_home_url_parse_query');
$q->query_vars['page_id'] = $sitepress_settings["urls"]["root_page"];
$q->query['page_id'] = $sitepress_settings["urls"]["root_page"];
$q->is_page = 1;
$q->queried_object = new WP_Post(get_post($sitepress_settings["urls"]["root_page"]));
$q->queried_object_id = $sitepress_settings["urls"]["root_page"];
$q->query_vars['error'] = "";
$q->is_404 = false;
$q->query['error'] = null;
}
return $q;
}
示例2: wptouch_custom_latest_post_filter
function wptouch_custom_latest_post_filter($query_vars)
{
if (wptouch_is_showing_mobile_theme_on_mobile_device()) {
$settings = foundation_get_settings();
if (foundation_is_theme_using_module('custom-latest-posts') && $settings->latest_posts_page != 'none') {
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($query_vars);
if ($dummy_query->is_page && count($query_vars) == 0) {
// Front page
$front_option = get_option('show_on_front', false);
if ($front_option == 'page') {
$front_page = get_option('page_on_front');
$dummy_query->queried_object_id = $front_page;
}
}
if (isset($dummy_query->queried_object_id) && apply_filters('foundation_is_custom_latest_posts_page', $settings->latest_posts_page == $dummy_query->queried_object_id)) {
if (isset($query_vars['paged'])) {
$paged = $query_vars['paged'];
} elseif (isset($query_vars['page'])) {
$paged = $query_vars['page'];
} else {
$paged = 1;
}
$query_vars = array('paged' => $paged, 'posts_per_page' => $settings->posts_per_page);
}
}
}
return $query_vars;
}
示例3: wptouch_custom_latest_post_filter
function wptouch_custom_latest_post_filter($query_vars)
{
if (wptouch_is_showing_mobile_theme_on_mobile_device()) {
$settings = foundation_get_settings();
if (foundation_is_theme_using_module('custom-latest-posts') && $settings->latest_posts_page != 'none') {
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($query_vars);
if ($dummy_query->is_page && count($query_vars) == 0) {
// Front page
$front_option = get_option('show_on_front', false);
if ($front_option == 'page') {
$front_page = get_option('page_on_front');
$dummy_query->queried_object_id = $front_page;
}
}
if (isset($dummy_query->queried_object_id) && apply_filters('foundation_is_custom_latest_posts_page', $settings->latest_posts_page == $dummy_query->queried_object_id)) {
if (isset($query_vars['paged'])) {
$paged = $query_vars['paged'];
} elseif (isset($query_vars['page'])) {
$paged = $query_vars['page'];
} else {
$paged = 1;
}
$query_vars = array('paged' => $paged, 'posts_per_page' => $settings->posts_per_page);
// Since we're modifying the query here, we need to prevent the custom landing page redirect from firing for this request (it'll think it's loading the homepage)
add_filter('wptouch_redirect_target', 'wptouch_return_false');
}
}
}
return $query_vars;
}
示例4: it_should_remove_date_filters_on_event_list
/**
* Event date & upcoming filters SHOULD be removed from event list pages (they do their own date filtering)
*
* @test
*/
public function it_should_remove_date_filters_on_event_list()
{
set_current_screen('edit-' . Tribe__Events__Main::POSTTYPE);
$query = new WP_Query();
$query->parse_query(['post_type' => Tribe__Events__Main::POSTTYPE]);
if (isset($_GET['page'])) {
unset($_GET['page']);
}
if (isset($_GET['tab'])) {
unset($_GET['tab']);
}
$this->assertTrue(Tribe__Events__Query::should_remove_date_filters($query), 'Date filters should be removed when on the event list page');
}
示例5: alter_the_query
/**
* Verified Voting functions and definitions
*/
function alter_the_query($request)
{
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($request);
// this is the actual manipulation; do whatever you need here
switch ($dummy_query->query_vars['pagename']) {
case 'blog':
$request['meta_key'] = 'verified_voting_blog';
$request['meta_value'] = true;
break;
case 'news':
$request['meta_key'] = 'the_voting_news';
$request['meta_value'] = true;
break;
}
return $request;
}
示例6: alter_request
/**
* Alternates request
*
* @param array $request
* @return array
*/
public function alter_request($request)
{
if (is_admin()) {
return $request;
}
$mapping = array();
foreach ($this->get_post_types() as $post_type) {
$page_id = (int) g1_get_theme_option('post_type_' . $post_type, 'page_for_posts');
if ($page_id) {
$mapping[$post_type] = $page_id;
}
}
foreach ($mapping as $post_type => $page_id) {
// WPML fallback
if (function_exists('icl_object_id')) {
$page_id = absint(icl_object_id($page_id, 'page', true));
}
if ($page_id) {
// The query isn't run if we don't pass any query vars
$query = new WP_Query();
$query->parse_query($request);
// Change request from page to post type archive
if ($query->is_page()) {
if (absint($query->get('page_id')) === $page_id || strlen($query->get('pagename')) && absint($query->get_queried_object_id()) === $page_id) {
unset($request['page']);
unset($request['page_id']);
unset($request['pagename']);
$request['post_type'] = $post_type;
}
}
}
}
return $request;
}
示例7: list_saved_layout
public static function list_saved_layout($storage_key = '')
{
global $wpdb;
self::set_storage_key($storage_key);
$storage_key = self::get_storage_key();
$layouts = $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE ( `option_name` LIKE '{$storage_key}-single%' OR `option_name` LIKE '{$storage_key}-archive%' )");
$return = array();
foreach ($layouts as $layout) {
if (preg_match("/^{$storage_key}-([^-]+)(-([^-]+)|)(-([^-]+)|)\$/", $layout->option_name, $match)) {
$ids = array();
if (!empty($match[3]) && !empty($match[5])) {
$ids['specificity'] = $match[1] . '-' . $match[3] . '-' . $match[5];
}
if ($match[3]) {
$ids['item'] = $match[1] . '-' . $match[3];
}
$ids['type'] = $match[1];
$layout_id = !empty($ids['specificity']) ? $ids['specificity'] : ($ids['item'] ? $ids['item'] : $ids['type']);
$return[$layout_id] = array('layout' => $ids, 'label' => Upfront_EntityResolver::layout_to_name($ids));
if ($ids['type'] == 'single') {
$query = new WP_Query(array('post_type' => $post_type->name, 'post_status' => 'publish'));
$query->parse_query();
$post = $query->next_post();
$return[$layout_id]['latest_post'] = $post->ID;
}
}
}
return $return;
}
示例8: test_parse_query_s_bool
public function test_parse_query_s_bool()
{
$q = new WP_Query();
$q->parse_query(array('s' => true));
$this->assertSame(true, $q->query_vars['s']);
}
示例9: graphene_exclude_slider_categories
/**
* Exclude posts that belong to the categories displayed in slider from the posts listing
*/
function graphene_exclude_slider_categories($request)
{
global $graphene_settings, $graphene_defaults;
if ($graphene_settings['slider_type'] != 'categories') {
return $request;
}
if (is_admin()) {
return $request;
}
if ($graphene_settings['slider_exclude_categories'] != $graphene_defaults['slider_exclude_categories']) {
$dummy_query = new WP_Query();
$dummy_query->parse_query($request);
if (get_option('show_on_front') == 'page' && $dummy_query->query_vars['page_id'] == get_option('page_on_front')) {
return $request;
}
if ($graphene_settings['slider_exclude_categories'] == 'everywhere' || $graphene_settings['slider_exclude_categories'] == 'homepage' && $dummy_query->is_home()) {
$request['category__not_in'] = graphene_object_id($graphene_settings['slider_specific_categories'], 'category');
}
}
return $request;
}
示例10: test_parse_query_p_object
/**
* @ticket 33372
*/
public function test_parse_query_p_object()
{
$q = new WP_Query();
$q->parse_query(array('p' => new stdClass()));
$this->assertSame('404', $q->query_vars['error']);
}
示例11: array
/**
* @param WP_Query $q
*
* @return mixed
*/
function wpml_home_url_parse_query($q)
{
if (!$q->is_main_query()) {
return $q;
}
if (!WPML_Root_Page::is_current_request_root()) {
return $q;
} else {
remove_action('parse_query', array($this, 'wpml_home_url_parse_query'));
$request_array = explode('/', $_SERVER["REQUEST_URI"]);
$sanitized_query = array_pop($request_array);
$potential_pagination_parameter = array_pop($request_array);
if (is_numeric($potential_pagination_parameter)) {
if ($sanitized_query) {
$sanitized_query .= '&';
}
$sanitized_query .= 'page=' . $potential_pagination_parameter;
}
$sanitized_query = str_replace('?', '', $sanitized_query);
$q->parse_query($sanitized_query);
add_action('parse_query', array($this, 'wpml_home_url_parse_query'));
$root_id = $this->get_root_page_id();
$q->query_vars['page_id'] = $root_id;
$q->query['page_id'] = $root_id;
$q->is_page = 1;
$q->queried_object = new WP_Post(get_post($root_id));
$q->queried_object_id = $root_id;
$q->query_vars['error'] = "";
$q->is_404 = false;
$q->query['error'] = null;
}
return $q;
}
示例12: alter_the_query
function alter_the_query($request)
{
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($request);
// this is the actual manipulation; do whatever you need here
if ($dummy_query->is_tag()) {
$request['post_type'] = array('post', 'product');
}
return $request;
}
示例13: wptouch_customizer_modify_homepage_query
function wptouch_customizer_modify_homepage_query($query_vars)
{
$settings = wptouch_get_settings();
$dummy_query = new WP_Query();
// the query isn't run if we don't pass any query vars
$dummy_query->parse_query($query_vars);
if (count($query_vars) == 0) {
// Front page
$query_vars['page_id'] = $settings->homepage_redirect_wp_target;
}
return $query_vars;
}
示例14: alter_event_page_request
/**
* Fix for events page rules if permalinks are disabled, unfortunatelly not too elegant.
*/
public function alter_event_page_request($request)
{
if (!is_admin() && !get_option('permalink_structure') && isset($request['page_id'])) {
$is_event_archive = false;
// WPML & Polylang
if (function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE')) {
if ((int) $request['page_id'] === (int) icl_object_id(Events_Maker()->options['general']['pages']['events']['id'], 'page', true, ICL_LANGUAGE_CODE)) {
$is_event_archive = true;
}
} elseif ((int) $request['page_id'] === (int) Events_Maker()->options['general']['pages']['events']['id']) {
$is_event_archive = true;
}
// is requested page an event archive page?
if ($is_event_archive === true) {
// the query isn't run if we don't pass any query vars
$query = new WP_Query();
$query->parse_query($request);
if ($query->is_page()) {
unset($request['page_id']);
$request['post_type'] = 'event';
}
}
}
return $request;
}
示例15: array
/**
* @param WP_Query $q
*
* @return mixed
*/
function wpml_home_url_parse_query($q)
{
if (!$q->is_main_query()) {
return $q;
}
if (!WPML_Root_Page::is_current_request_root()) {
return $q;
} else {
remove_action('parse_query', array($this, 'wpml_home_url_parse_query'));
$request_array = explode('/', $_SERVER['REQUEST_URI']);
$sanitized_query = array_pop($request_array);
$potential_pagination_parameter = array_pop($request_array);
if (is_numeric($potential_pagination_parameter)) {
if ($sanitized_query) {
$sanitized_query .= '&';
}
$sanitized_query .= 'page=' . $potential_pagination_parameter;
}
$sanitized_query = str_replace('?', '', $sanitized_query);
$q->parse_query($sanitized_query);
$root_id = $this->get_root_page_id();
add_action('parse_query', array($this, 'wpml_home_url_parse_query'));
if (false !== $root_id) {
$q = $this->set_page_query_parameters($q, $root_id);
} else {
$front_page = get_option('page_on_front');
if ($front_page) {
$q = $this->set_page_query_parameters($q, $front_page);
}
}
}
return $q;
}