I’m filtering the main query of Jigoshop with my own taxonomy with this hook (The file responsible for Jigoshop queries that I’m hooking, Jigoshop hooks onto WP ‘request’ filter):
add_filter( 'loop_shop_tax_query', 'my_loop_shop_tax_query', 11 );
function loop_shop_tax_query( $request )
{
$region = 'dublin';
if ( ! empty( $region ) ) {
$request[] = array(
'taxonomy' => 'product_region',
'field' => 'slug',
'terms' => $region,
'operator' => 'IN',
);
}
return $request;
}
I want to filter every Jigoshop query this way (all products display, category display & search display). This is working as intended but wp_title() in the html head is causing the error:
Notice: Undefined property: stdClass::$labels in /var/www/wp/wp-includes/general-template.php on line 658
Notice: Trying to get property of non-object in /var/www/wp/wp-includes/general-template.php on line 658
I’ve tracked this down in general-template.php and is_post_type_archive()
is returning true even though get_tax()
is also returning true. get_queried_object()
is returning my taxonomy object (normally the Jigoshop product custom post type object).
I need get_queried_object()
to still return the Jigoshop product custom post type object and get_tax()
should return false, I want to filter the posts with my taxonomy but I want to keep displaying a post type archive (is this even possible?)
Just before the request is sent back to WP for ‘request’ filter, it looks like this:
Array ( [post_type] => product [post_status] => publish [posts_per_page] => 12 [orderby] => post_date [order] => asc [tax_query] => Array ( [relation] => AND [0] => Array ( [taxonomy] => product_region [field] => slug [terms] => dublin [operator] => IN ) ) [meta_query] => Array ( [0] => Array ( [key] => visibility [value] => Array ( [0] => visible [1] => catalog ) [compare] => IN ) ) [post__in] => Array ( [0] => 293 [1] => 291 [2] => 289 [3] => 18 [4] => 0 ) )
I hope this isn’t too specific and makes sense, I’m really at my wit’s end here, any help would be greatly appreciated.
The simplest way is, in all honesty, to hook into
wp_title
and change things, and just be aware that the warnings are there but not showing in production (because you’ve property configured your server).What follows is a kind of hacky solution.
If you take a look at
get_queried_object
…Just a thin wrapper around
WP_Query::get_queried_object
, so let’s take a look at that.As you can see, WordPress checks a bunch of stuff to see just what type of query this is and where it’s set. The first check is to see if this is a category, tag, or taxonomy archive. Since that succeeds, the post type archive object is never set.
What’s really weird is why both
is_post_type_archive
andis_tax
are returning true. Due to the wayWP_Query::parse_query
works, it’s possible that an archive can be both a post type archive as well as a taxonomy archive.Anyway,
WP_Query::$queried_object
is a public property, do just hook into someplace beforewp_title
fires and replace it.template_redirect
would work.This is very much a hack, but there’s no
pre_wp_title
filter or the like where you could prevent the warnings. Untested example below. Be aware that if the WP core decides to make$queried_object
a private or protected property in future release this will not work. It could also negatively impact other areas of your site.