本文整理汇总了PHP中WP_Query::is_tax方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::is_tax方法的具体用法?PHP WP_Query::is_tax怎么用?PHP WP_Query::is_tax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::is_tax方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _fw_ext_portfolio_theme_action_set_posts_per_page
/**
* Display all existing portfolio posts on the page (without pagination)
* Because in this theme we use the https://mixitup.kunkalabs.com/ plugin to display portfolio posts
* If your theme displays portfolio posts in a different way, feel free to change or remove this function
* @internal
* @param WP_Query $query
*/
function _fw_ext_portfolio_theme_action_set_posts_per_page($query)
{
if (!$query->is_main_query()) {
return;
}
/**
* @var FW_Extension_Portfolio $portfolio
*/
$portfolio = fw()->extensions->get('portfolio');
$is_portfolio_taxonomy = $query->is_tax($portfolio->get_taxonomy_name());
$is_portfolio_archive = $query->is_archive() && isset($query->query['post_type']) && $query->query['post_type'] == $portfolio->get_post_type_name();
if ($is_portfolio_taxonomy || $is_portfolio_archive) {
$query->set('posts_per_page', -1);
}
}
示例2: is_pronamic_events_query
/**
* Check if the query is requesting event post type
*
* @param WP_Query $query
* @return boolean true if events are queried, false otherwises
*/
function is_pronamic_events_query(WP_Query $query)
{
$is_pronamic_events = false;
if ($query->is_archive() && !$query->is_tax('pronamic_event_status')) {
// Check 'post_type' var
// Note: post_type could also be an array
$post_type = $query->get('post_type');
if (!empty($post_type) && !is_array($post_type)) {
$is_pronamic_events = post_type_supports($post_type, 'pronamic_event');
}
if (!$is_pronamic_events) {
// Check queried object
$object = $query->get_queried_object();
$is_pronamic_events = isset($object, $object->name) && post_type_supports($object->name, 'pronamic_event');
}
}
return $is_pronamic_events;
}
示例3: array
/**
* Get the fork's parent post, set up a query, and load correct template.
*
* Duplicates the functionality of /wp-includes/template-loader.php and includes
* a lot of copypasta, but that's only to ensure that it follows the same logic.
*
*/
function choose_template()
{
$p = get_queried_object_id();
if (get_post_type($p) !== 'fork') {
return;
}
$pp = get_post($p)->post_parent;
$parent = get_post($pp);
if ($parent->post_type == 'page') {
$query = array('page_id' => $pp);
} else {
$query = array('p' => $pp);
}
$t = new WP_Query($query);
$template = false;
if ($t->is_404() && ($template = get_404_template())) {
} elseif ($t->is_search() && ($template = get_search_template())) {
} elseif ($t->is_tax() && ($template = get_taxonomy_template())) {
} elseif ($t->is_front_page() && ($template = get_front_page_template())) {
} elseif ($t->is_home() && ($template = get_home_template())) {
} elseif ($t->is_attachment() && ($template = get_attachment_template())) {
remove_filter('the_content', 'prepend_attachment');
} elseif ($t->is_single() && ($template = get_single_template())) {
} elseif ($t->is_page && ($template = get_page_template())) {
} elseif ($t->is_category() && ($template = get_category_template())) {
} elseif ($t->is_tag() && ($template = get_tag_template())) {
} elseif ($t->is_author() && ($template = get_author_template())) {
} elseif ($t->is_date() && ($template = get_date_template())) {
} elseif ($t->is_archive() && ($template = get_archive_template())) {
} elseif ($t->is_comments_popup() && ($template = get_comments_popup_template())) {
} elseif ($t->is_paged() && ($template = get_paged_template())) {
} else {
$template = get_index_template();
}
if ($template = apply_filters('template_include', $template)) {
include $template;
}
return;
}
示例4: the_posts
/**
* Hook into the_posts to do the main product query if needed - relevanssi compatibility
*
* @access public
* @param array $posts
* @param WP_Query|bool $query (default: false)
* @return array
*/
public function the_posts($posts, $query = false)
{
// Abort if there's no query
if (!$query) {
return $posts;
}
// Abort if we're not filtering posts
if (empty($this->post__in)) {
return $posts;
}
// Abort if this query has already been done
if (!empty($query->wc_query)) {
return $posts;
}
// Abort if this isn't a search query
if (empty($query->query_vars["s"])) {
return $posts;
}
// Abort if we're not on a post type archive/product taxonomy
if (!$query->is_post_type_archive('product') && !$query->is_tax(get_object_taxonomies('product'))) {
return $posts;
}
$filtered_posts = array();
$queried_post_ids = array();
foreach ($posts as $post) {
if (in_array($post->ID, $this->post__in)) {
$filtered_posts[] = $post;
$queried_post_ids[] = $post->ID;
}
}
$query->posts = $filtered_posts;
$query->post_count = count($filtered_posts);
// Ensure filters are set
$this->unfiltered_product_ids = $queried_post_ids;
$this->filtered_product_ids = $queried_post_ids;
if (sizeof($this->layered_nav_post__in) > 0) {
$this->layered_nav_product_ids = array_intersect($this->unfiltered_product_ids, $this->layered_nav_post__in);
} else {
$this->layered_nav_product_ids = $this->unfiltered_product_ids;
}
return $filtered_posts;
}
示例5: foreach
/**
* @param string $where
* @param WP_Query $query
*
* @return string
*/
function posts_where_filter($where, $query)
{
global $pagenow, $wp_taxonomies, $sitepress, $sitepress_settings;
//exceptions
$post_type = false;
if (isset($query->queried_object) && isset($query->queried_object->ID) && $query->queried_object->ID == $sitepress_settings['urls']['root_page']) {
return $where;
}
// determine post type
$debug_backtrace = $this->get_backtrace(0, true, false);
//Limit to a maximum level?
foreach ($debug_backtrace as $o) {
if ($o['function'] == 'apply_filters_ref_array' && $o['args'][0] == 'posts_where') {
$post_type = $o['args'][1][1]->query_vars['post_type'];
break;
}
}
// case of taxonomy archive
if (empty($post_type) && $query->is_tax()) {
$tax = $query->get('taxonomy');
$post_type = $wp_taxonomies[$tax]->object_type;
foreach ($post_type as $k => $v) {
if (!$this->is_translated_post_type($v)) {
unset($post_type[$k]);
}
}
if (empty($post_type)) {
return $where;
}
// don't filter
}
if (!$post_type) {
$post_type = 'post';
}
if (is_array($post_type) && !empty($post_type)) {
$none_translated = true;
foreach ($post_type as $ptype) {
if ($this->is_translated_post_type($ptype)) {
$none_translated = false;
}
}
if ($none_translated) {
return $where;
}
} else {
if (!$this->is_translated_post_type($post_type) && 'any' != $post_type) {
return $where;
}
}
$attachment_is_translatable = $sitepress->is_translated_post_type('attachment');
if (($pagenow == 'upload.php' || $pagenow == 'media-upload.php' || $query->is_attachment()) && !$attachment_is_translatable) {
return $where;
}
$current_language = $sitepress->get_current_language();
$requested_id = false;
// Fix for when $sitepress->get_current_language() does not return the correct value (e.g. when request is made for an attachment, an iframe or an ajax call)
if (isset($_REQUEST['attachment_id']) && $_REQUEST['attachment_id']) {
$requested_id = $_REQUEST['attachment_id'];
}
if (isset($_REQUEST['post_id']) && $_REQUEST['post_id']) {
$requested_id = $_REQUEST['post_id'];
}
if ($requested_id) {
$post_type = get_post_type($requested_id);
$current_language = $sitepress->get_language_for_element($requested_id, 'post_' . $post_type);
if (!$current_language) {
$current_language = $sitepress->get_current_language();
}
}
if ('all' != $this->this_lang) {
if ('any' == $post_type) {
$condition = " AND (t.language_code='" . esc_sql($current_language) . "' OR t.language_code IS NULL )";
} else {
$condition = " AND t.language_code='" . esc_sql($current_language) . "'";
}
} else {
$condition = '';
}
$where .= $condition;
return $where;
}
示例6: tax_post_types_from_query
/**
* @param WP_Query $query
* @return String[]
*/
private function tax_post_types_from_query($query)
{
if ($query->is_tax() && $query->is_main_query()) {
$taxonomy_post_types = $this->get_tax_query_posttype($query);
} else {
$taxonomy_post_types = array_keys($this->sitepress->get_translatable_documents(false));
}
return $taxonomy_post_types;
}
示例7: extract_tax_archive_data
/**
* @param WP_Query $wp_query
*
* @return array()
*/
private function extract_tax_archive_data($wp_query)
{
$taxonomy = false;
$term_id = false;
if ($wp_query->is_category()) {
$taxonomy = 'category';
$term_id = $wp_query->get('cat');
} elseif ($wp_query->is_tag()) {
$taxonomy = 'post_tag';
$term_id = $wp_query->get('tag_id');
} elseif ($wp_query->is_tax()) {
$taxonomy = $wp_query->get('taxonomy');
$term_id = $wp_query->get_queried_object_id();
}
return array($taxonomy, $term_id);
}
示例8: filter_query
/**
* Filter post type archive view queries.
*
* - Projects and entities are sorted by title.
* - People are sorted by last name.
* - Publications are left to a default sort by date.
* - All posts_per_page limits are bumped to 2000.
*
* @param WP_Query $query
*/
public function filter_query($query)
{
if (!$query->is_main_query() || is_admin()) {
return;
}
$post_types = $this->get_object_type_slugs();
// Avoid paginating without intent by maxing out at 2000 per archive.
if ($query->is_post_type_archive($post_types)) {
$query->set('posts_per_page', 2000);
}
// Avoid pagination without intent by maxing out at 2000 per taxonomy archive.
if ($query->is_tax($this->entity_type_taxonomy) || $query->is_tax($this->topics_taxonomy)) {
$query->set('posts_per_page', 2000);
}
// Entities and projects are sorted by their titles in archive views.
if ($query->is_tax($this->topics_taxonomy) || $query->is_tax($this->entity_type_taxonomy) || $query->is_post_type_archive($this->entity_content_type) || $query->is_post_type_archive($this->project_content_type)) {
$query->set('orderby', 'title');
$query->set('order', 'ASC');
}
// People are sorted by their last names in archive views.
if ($query->is_post_type_archive($post_types) && $query->is_post_type_archive($this->people_content_type)) {
$query->set('meta_key', '_wsuwp_uc_person_last_name');
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
}
}
开发者ID:washingtonstateuniversity,项目名称:WSUWP-Plugin-University-Center,代码行数:36,代码来源:wsuwp-university-center.php
示例9: alter_taxonomy_archive
/**
* Alternates the 'posts_per_page' query_var on taxonomy archive pages
*
* @todo Correct taxonomy value ?
*
* @param WP_Query $query
*/
public function alter_taxonomy_archive($query)
{
if (is_admin() || !$query->is_main_query()) {
return;
}
if (!($query->is_tax() || $query->is_category() || $query->is_tag())) {
return;
}
if (is_tax()) {
// Get query var
$taxonomy = $query->tax_query->queries[0]['taxonomy'];
$tax_obj = get_taxonomy($taxonomy);
$query_var = $tax_obj->query_var;
if ($query->get($taxonomy)) {
$term = get_term_by('slug', $query->get($query_var), $taxonomy);
}
} elseif (is_category()) {
$taxonomy = 'category';
if ($query->get('cat')) {
$term = get_term($query->get('cat'), 'category');
} elseif ($query->get('category_name')) {
$term = get_term_by('slug', $query->get('category_name'), 'category');
}
} elseif (is_tag()) {
$taxonomy = 'post_tag';
if ($query->get('tag_id')) {
$term = get_term($query->get('tag_id'), 'post_tag');
} else {
$term = get_term_by('slug', $query->get('tag'), 'post_tag');
}
}
if (taxonomy_supports($taxonomy, $this->global_feature)) {
$posts_per_page = (int) g1_get_theme_option('taxonomy_' . $taxonomy, 'posts_per_page');
if (-1 === $posts_per_page || $posts_per_page > 0) {
$query->set('posts_per_page', $posts_per_page);
}
}
if (taxonomy_supports($taxonomy, $this->individual_feature)) {
if ($term) {
$term_meta = (array) g1_get_term_meta($term->term_id, '_g1');
$posts_per_page = isset($term_meta['posts_per_page']) ? (int) $term_meta['posts_per_page'] : 0;
if (-1 === $posts_per_page || $posts_per_page > 0) {
$query->set('posts_per_page', $posts_per_page);
}
}
}
}
示例10: getPageObject
/**
* Parse which page we are on using URL
*/
public function getPageObject($pageUrl)
{
global $wp_rewrite;
// If post type, we are using url_to_postid function
$postId = url_to_postid($pageUrl);
if ($postId) {
$postType = get_post_type_object(get_post($postId)->post_type);
return array('value' => $postId, 'title' => get_the_title($postId), 'type' => get_post($postId)->post_type, 'label' => is_array($postType->labels) ? $postType->labels['name'] : $postType->labels->name);
}
$path = str_replace(get_site_url(), '', $pageUrl);
$path = trim($path, '/');
// If path is empty, then it is front page
if (empty($path)) {
return array('value' => get_option('page_on_front') ? get_option('page_on_front') : '', 'title' => '', 'type' => 'front_page', 'label' => __('Home Page'));
}
// Otherwise, we will try to match through rewrite or by query
$rewrite = $wp_rewrite->wp_rewrite_rules();
if (is_array($rewrite) && count($rewrite) > 0) {
foreach ($rewrite as $match => $query) {
if (preg_match("#^{$match}#", $path, $matches) || preg_match("#^{$match}#", urldecode($path), $matches)) {
$query = preg_replace("!^.*\\?!", '', $query);
$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
parse_str($query, $query_vars);
break;
}
}
} else {
$query = preg_replace("!^.*\\?!", '', $path);
parse_str($query, $query_vars);
}
// Workaround for fail pagename rewrite match
if (isset($query_vars['pagename']) && strpos($query_vars['pagename'], '?') !== false) {
$query = preg_replace("!^.*\\?!", '', $query_vars['pagename']);
parse_str($query, $query_vars);
}
$querypost = new WP_Query($query_vars);
if ($querypost->is_date()) {
if ($querypost->query_vars['m']) {
$date = $querypost->query_vars['m'];
} else {
if ($querypost->is_day()) {
$date = $querypost->query_vars['year'] . zeroise($querypost->query_vars['monthnum'], 2) . zeroise($querypost->query_vars['day'], 2);
} else {
if ($querypost->is_month()) {
$date = $querypost->query_vars['year'] . zeroise($querypost->query_vars['monthnum'], 2);
} else {
if ($querypost->is_year()) {
$date = $querypost->query_vars['year'];
}
}
}
}
return array('value' => $date, 'title' => '', 'type' => 'archive', 'label' => __("Archive"));
} else {
if ($querypost->is_category() || $querypost->is_tag() || $querypost->is_tax()) {
$tax_query = $querypost->tax_query->queries;
$taxonomy = get_taxonomy($tax_query[0]['taxonomy']);
if ($tax_query[0]['field'] == 'term_id') {
$term_id = $tax_query[0]['terms'][0];
} else {
if ($tax_query[0]['field'] == 'slug') {
$term_id = get_term_by('slug', $tax_query[0]['terms'][0], $taxonomy->name)->term_id;
}
}
return array('value' => $term_id, 'title' => get_term($term_id, $taxonomy->name)->name, 'type' => $taxonomy->name, 'label' => is_array($taxonomy->labels->name) ? $taxonomy->labels['name'] : $taxonomy->labels->name);
} else {
if ($querypost->is_search()) {
return array('value' => $querypost->query_vars['s'], 'title' => '', 'type' => 'search', 'label' => __("Search"));
} else {
if ($querypost->is_home()) {
return array('value' => '', 'title' => '', 'type' => 'home', 'label' => __("Blog Home Page"));
}
}
}
}
}
示例11: adverts_posts_results
/**
* Replaces Main Query objects.
*
* When browsing by category by default WP will display list of categories
* (depending on the theme), we do not want that, instead we want to take control
* over the page content. In order to do that this function removes main query
* list of terms and replaces them with post that holds adverts list.
*
* @param array $posts
* @param WP_Query $query
* @return array Post objects
*/
function adverts_posts_results($posts, $query)
{
if ($query->is_main_query() && $query->is_tax("advert_category")) {
$title = sprintf(__("Category: %s", "adverts"), $query->get_queried_object()->name);
$post = get_post(adverts_config('config.ads_list_id'));
$post->post_title = apply_filters("adverts_category_the_title", $title);
return array($post);
} else {
return $posts;
}
}
示例12: array
/**
* used by the layered_nav widget and the price filter widget as they access the global ($all_post_ids)
* is run on the 'request' filter with highest priority to ensure it runs before main filter_catalog_query
* gathers all product ID's into a global variable for use elsewhere ($all_post_ids)
*
* @param array $request - the array representing the current WordPress request eg. post_type => 'product'
* @return array - unaltered array of the intial request
* @since 0.9.9
**/
function jigoshop_get_product_ids_in_view($request)
{
global $jigoshop_all_post_ids_in_view;
$jigoshop_all_post_ids_in_view = array();
$this_query = new WP_Query();
$this_query->parse_query($request);
if ($this_query->is_post_type_archive('product') || $this_query->is_tax('product_cat') || $this_query->is_tax('product_tag')) {
$args = array_merge($this_query->query, array('page_id' => '', 'fields' => 'ids', 'posts_per_page' => -1, 'post_type' => 'product', 'post_status' => 'publish', 'meta_query' => self::meta_query($this_query)));
$custom_query = get_posts($args);
$jigoshop_all_post_ids_in_view = array_merge($jigoshop_all_post_ids_in_view, $custom_query);
}
$jigoshop_all_post_ids_in_view[] = 0;
return $request;
}
示例13: defineLookupOrder
/**
* The rule of this ordering is: from the most specific to the least.
* Most of the default WP Template Hierarchy is the same, but not all is followed.
*
* For the full example of our lookup order plesase follow to:
*
* For the default WP hierarchy follow to:
* http://codex.wordpress.org/Template_Hierarchy
*
* @param WP_Query $wp_query
* @return array
*/
protected function defineLookupOrder(\WP_Query $wp_query)
{
$result = [];
if (!$wp_query) {
return $result;
}
// prepare vars
$post = !empty($wp_query->posts) ? $wp_query->posts[0] : false;
$post_type = $post ? $post->post_type : false;
$post_slug = $post ? $post->post_name : false;
$query_post_type = $wp_query->query_vars['post_type'];
if (is_array($query_post_type)) {
// it's not usual to have multiple post types on a rewrite rule
// but even if there is, it's extremely inconsistent to rely on
// a template name with multiple post types
// if that's the case, the user will have to alter the template
// order manually
$query_post_type = false;
}
// start the template hierarchy build up
if ($wp_query->is_404()) {
// 404-[post-type]
// 404
if ($query_post_type) {
$result[] = '404-' . $query_post_type;
}
$result[] = '404';
} elseif ($wp_query->is_search()) {
// search
// archive
$result[] = 'search';
$result[] = 'archive';
} elseif ($wp_query->is_front_page()) {
// if is page on front:
// front-page
// page
// singular
// if is posts on front:
// front-page
// home
// archive-[post-type]
// [post-type]
// archive
$result[] = 'front-page';
if ($post_type) {
if ($post_type !== 'page') {
$result[] = 'home';
$result[] = 'archive-' . $post_type;
$result[] = $post_type;
$result[] = 'archive';
} else {
$result[] = 'page';
$result[] = 'singular';
}
}
} elseif ($wp_query->is_home()) {
// home
// archive-[post-type]
// [post-type]
// archive
$result[] = 'home';
if ($post_type) {
$result[] = 'archive-' . $post_type;
$result[] = $post_type;
$result[] = 'archive';
}
// for now this is not needed, test more
// } elseif ($wp_query->is_post_type_archive()) {
// $result[] = 'archive-'.$query_post_type;
// $result[] = $query_post_type;
// $result[] = 'archive';
} elseif ($wp_query->is_author()) {
// author-[user-login]
// author-[user-nicename]
// author
// archive
if ($author = get_userdata($post->post_author)) {
$result[] = 'author-' . $author->data->user_login;
if ($author->data->user_login !== $author->data->user_nicename) {
$result[] = 'author-' . $author->data->user_nicename;
}
}
$result[] = 'author';
$result[] = 'archive';
} elseif ($wp_query->is_tax() || $wp_query->is_tag() || $wp_query->is_category()) {
// taxonomy-[taxonomy]-[term-slug]
// taxonomy-[taxonomy]
// taxonomy-[post-type]
//.........这里部分代码省略.........