Pre_get_posts and tag archive
-
Hi, I’m redesigning a podcast site that uses a tag to differentiate between podcast episodes and blog posts. The tag archives should ONLY show blog posts, so I to use pre_get posts so that only posts that contain a certain other tag will be shown. The problem is that when I do that, the_archive_title() and the_archive_description() think I’m querying that specific tag I’m using to filter, so the wrong information shows up.
I realise that it would be easier to use custom post types to differentiate between podcast and blog posts, but this site already has over 2000 posts and that’s the way they’ve been doing it, and I want to disrupt the content uploaders’ workflow as little as possible.
This is my current code:
function rhap_pre_get_posts( $query ) { //Don't change in WordPress admin if ( is_admin() || ! $query->is_main_query() ) return; //Exclude blog tag from main query in category archives if ( $query->is_main_query() && $query->is_tag() ) { $query->set( 'tag_id', 1284 ); return; } } add_action( 'pre_get_posts', 'rhap_pre_get_posts', 1 );
Thanks!
- The topic ‘Pre_get_posts and tag archive’ is closed to new replies.