For example, http://example.com/?cat=6&tag=books
lists posts that belong to category ID 6 and tagged 'books' (i.e. posts that satisfy both conditions).
Similarly, http://example.com/feed/?cat=6&tag=books
does the same for feeds.
Now, lets say that my blog has a custom taxonomy called 'edition', with terms 'usa', 'uk', 'china', and so on, under it. The URL http://example.com/?edition=usa,china
lists posts that belong to both editions 'usa' and 'china'.
And http://example.com/category/cars/?edition=usa
lists those posts from category 'Cars' that also belong to the custom taxonomy term 'usa'.
The problem
I use the code below in my functions.php:
add_filter('pre_get_posts','better_editions_archive');
function better_editions_archive( $better_editions_query ) {
/* Looks like this line needs to be changed, not sure how */
if ( $better_editions_query->is_tax( 'edition' ) && $better_editions_query->is_main_query() ) {
$better_editions_terms = get_terms( 'edition', array( 'fields' => 'ids' ) );
$better_editions_query->set( 'post_type', array( 'post' ) );
$better_editions_query->set( 'tax_query',
array(
'relation' => 'OR',
array(
'taxonomy' => 'edition',
'field' => 'id',
'terms' => $better_editions_terms,
'operator' => 'NOT IN'
)
)
);
}
return $better_editions_query;
}
The code makes sure that if a post is unassigned to any Edition (i.e. if a post is not assigned to any term that belongs to the custom taxonomy 'edition'), the post is shown/listed under all term archives/feeds of the custom taxonomy 'edition'.
Now, http://example.com/category/cars/?edition=usa
only lists posts that belong to the category 'cars' and specifically marked 'usa' (a term belonging to the custom taxonomy 'edition'). It doesn't show those posts that aren't assigned to any term in the custom taxonomy 'edition'. How do I fix this?
(PS: Setting default terms for posts isn't an option, as we may add more editions later on.)
Solved but...
I've worked out a solution which you can see as an answer to this question. The bounty still stands, so feel free. :)
global $wp; $wp->add_query_var('author_more');
http://example.com/category/cars/?edition=usa