我刚刚从4.2升级到4.4,现在我的分类查询返回空。在升级之前,它一直运行良好。
我已经注册了一个名为\'title\'
, 由我的自定义帖子类型使用\'sg-publications\'
. 根据WP模板层次结构,我创建了一个名为taxonomy-title.php
它使用默认的查询参数,并且到目前为止已按标题正确显示了每个出版物。
以下是该模板中$queryed\\u object和$wp\\u query->request的输出:
[queried_object] => WP_Term Object
(
[term_id] => 1256
[name] => Stroupe Scoop
[slug] => stroupe-scoop
[term_group] => 0
[term_taxonomy_id] => 1374
[taxonomy] => title
[description] =>
[parent] => 0
[count] => 30
[filter] => raw
)
[queried_object_id] => 1256
[request] =>
SELECT wp_posts.*
FROM wp_posts
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE 1=1
AND wp_posts.post_title = \'stroupe-scoop\'
AND (
wp_term_relationships.term_taxonomy_id
IN (1374)
)
AND wp_posts.post_type = \'sg-publications\'
AND (wp_posts.post_status = \'publish\'
OR wp_posts.post_status = \'private\'
)
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date
DESC
我在上面的查询中看到的问题是
WHERE 1=1
, 出于某种原因,它正在搜索
post_title = \'stroupe-scoop\'
. 这是不正确的-这是分类术语slug,而不是文章的标题。事实上,当我注释掉这一行并对数据库运行它时,我得到了正确的返回。那么,是什么原因导致WP添加了那个条件,而(我假设)在我升级到4.4之前它并没有添加那个条件呢?
这是分类标题。php:
<?php
/**
* @package WordPress
* @subpackage Chocolate
*/
global $wp_query;
$quer_object = get_queried_object();
$tax_desc = $quer_object->description;
$tax_name = $quer_object->name;
$tax_slug = $quer_object->slug;
get_header();
get_sidebar();
$title = get_the_title( $ID );
$args = array(
\'menu\' => \'new-publications\',
\'container\' => \'div\',
\'container_id\' => $tax_slug . \'-menu\',
\'menu_class\' => \'menu-top-style nav nav-tab\',
\'menu_id\' => \'\',
\'echo\' => true,
\'fallback_cb\' => false,
\'before\' => \'\',
\'after\' => \'\',
\'link_before\' => \'<i class="fa fa-chevron-circle-right fa-fw fa-2x"></i>\',
\'link_after\' => \'\',
\'items_wrap\' => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
\'depth\' => 0,
\'walker\' => \'\'
);
?>
<div id="page-title">
<h1><?php _e( \'Publications - \' . $tax_name, LANGUAGE_ZONE ); ?></h1>
<p><?php _e( \'View our monthly newsletter and stay informed on the latest real estate news.\', LANGUAGE_ZONE ); ?></p>
<?php wp_nav_menu($args); ?>
</div>
<div id="multicol">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( \'loop\' , \'title\' );
endwhile;
endif;
?>
</div><!-- end #multicol -->
<section class="page-text well"><?php _e( $tax_desc, LANGUAGE_ZONE ); ?></section>
<?php
get_footer();
和在函数中。php我有这个查询过滤器:
// use pre_get_posts to remove pagination from publications
function gd_publications_pagination( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_tax(\'title\') ) {
// Display all posts for the taxonomy called \'title\'
$query->set( \'posts_per_page\', -1 );
return;
}
}
add_action( \'pre_get_posts\', \'gd_publications_pagination\', 1 );