I just upgraded from 4.2 to 4.4 and now my taxonomy query returns empty. It has been working fine prior to the upgrade.
I have registered a custom taxonomy named 'title'
, which is used by my custom post type 'sg-publications'
. Following the WP template hierarchy I created a template called taxonomy-title.php
which uses the default query args, and up until now has correctly shown each publication by it's title.
Here is the output of $queried_object and $wp_query->request in that template:
[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
The problem I see in the above query is right after WHERE 1=1
, for some reason it is searching for post_title = 'stroupe-scoop'
. This is not correct - that is the taxonomy term slug, not the title of the post. In fact, when I comment out that line and run it against the database I get the proper returns. So what is causing WP to add that condition, when (I assume) it was not adding it before I upgraded to 4.4?
Here is taxonomy-title.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();
And in functions.php I have this query filter:
// 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 );
taxonomy-title.php
? Did you look in theme'sfunctions.php
to check if there are any filters on the main query?