Tagged: archive, Blog, Custom Post Type, posts, tag
-
AuthorPosts
-
April 17, 2023 at 8:39 am #1404649
Dear Support-Team,
I am wondering if I could filter the query for tag archives. I am using this code for the masonry element:
function avia_masonry_custom_query( $query ) { unset($query['post_type']['ABC']); // Custom Post Type "ABC" $exclude_cat = array('category__not_in' => array( 1, 2 )); // Categories by ID $query = array_merge((array)$exclude_cat, (array)$query); return $query; } add_filter('avia_masonry_entries_query', 'avia_masonry_custom_query');
Is there a filter for the blog post element or even tag archives too? I have a certain tag archive with posts from different post types and I would like to strip all posts from one of the post types from the archive.
Any ideas?
All the best, Daniel
April 25, 2023 at 9:44 pm #1405601Any advice on how to implement a filter for tag archives (see above)? I have a certain tag archive with posts from different post types and I would like to strip all posts from one of the post types from the archive.
April 27, 2023 at 9:12 am #1405785Hi,
Sorry for the late reply.
To modify the main query for archive you can use the pre_get_posts filter. An example how we use it to modify the search query is here:
For the ALB blog element we have the filter avia_blog_post_query.
Hope this helps you.
Best regards,
GünterApril 27, 2023 at 9:54 am #1405788Hey Günter,
thank you for getting back to me and thanks for the code snippet.
So instead of
if( $query->is_search )
I would somehow check if it is a certain post type archive instead ofis_search
– correct? The rest of the code is the same? Could I write something likeif( $query->is_tax('test')
and later on define which post type is the only one to query in this archive?Best regards,
DanielApril 27, 2023 at 10:55 am #1405803Hi,
Definition of is_tax():
I would say yes, this should be the way (but I did not test it).
Best regards,
Günter -
AuthorPosts
- You must be logged in to reply to this topic.