Per this question (How to create an attachments archive with working pagination?), I've been using the following function to have archive pages display attachments as well as pages and posts. It was working for the preexisting tag and category archive pages, but it stopped working a few weeks ago (possibly due to a Wordpress update, but I didn't notice at the time). I checked, and the post_tag
and category
taxonomies are still registered for attachments.
This code still works to display attachments in the archive pages of custom taxonomies (topic
and training
below). Any ideas on what changed, and what to change to get this working again?
add_action('parse_query', 'hijack_query');
function hijack_query() {
global $wp_query;
// When inside a custom taxonomy archive, include attachments AS WELL AS pages and posts.
// Note that is_tax() returns false on category archives and tag archives. Use is_category() and is_tag() respectively when checking for category and tag archives.
if (is_tax('topic') OR is_tax('training') OR is_tag() OR is_category()) {
$wp_query->query_vars['post_type'] = array( 'attachment', 'page', 'post' );
$wp_query->query_vars['post_status'] = array( null );
return $wp_query;
}
}