当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Query::parse_query方法代码示例

本文整理汇总了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;
}
开发者ID:tlandn,项目名称:akvo-sites-zz-template,代码行数:43,代码来源:home-url-functions.php

示例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;
}
开发者ID:sumwander,项目名称:unyil,代码行数:30,代码来源:custom-latest-posts.php

示例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;
}
开发者ID:yarylo,项目名称:cerkva.pp.ua,代码行数:32,代码来源:custom-latest-posts.php

示例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');
 }
开发者ID:reubenbrown13,项目名称:the-events-calendar,代码行数:18,代码来源:Date_Filter_Test.php

示例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;
}
开发者ID:radicaldesigns,项目名称:verified_voting_wp,代码行数:21,代码来源:functions.php

示例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;
 }
开发者ID:aragonc,项目名称:3clicks,代码行数:40,代码来源:features.php

示例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;
 }
开发者ID:sedici,项目名称:wpmu-istec,代码行数:29,代码来源:class_upfront_layout.php

示例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']);
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:6,代码来源:parseQuery.php

示例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;
}
开发者ID:kosir,项目名称:thatcamp-org,代码行数:24,代码来源:theme-slider.php

示例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']);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:9,代码来源:parseQuery.php

示例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;
 }
开发者ID:aarongillett,项目名称:B22-151217,代码行数:38,代码来源:wpml-root-page-actions.class.php

示例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;
}
开发者ID:Haber-He,项目名称:wp-theme-sky,代码行数:11,代码来源:functions.php

示例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;
}
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:12,代码来源:wptouch-customizer.php

示例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;
 }
开发者ID:patlegris,项目名称:On-Off,代码行数:28,代码来源:class-query.php

示例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;
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:38,代码来源:wpml-root-page-actions.class.php


注:本文中的WP_Query::parse_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。