Tagged: posts categories
-
AuthorPosts
-
May 24, 2023 at 3:44 pm #1408433
Hi,
i need help with the element “Blog Posts”, i want to display posts that are assigned to category1 AND category2.If the post is in category1 and not in category2 then don´t display the post.
If the post is not in category1 and in category2 then don´t display the post.
If the post is in category1 and in category2 then display the post.If i configure “Select Entries” in the Blog Posts element with “Display blog posts” and select the two categories the page shows posts from category1 OR/AND category2, but i need only the posts that in category1 AND category2.
The Filter > Offset Number > Do not allow duplicate post on the entire page (set offset automatically) don´t help me.
How is it possible to display posts that are assigned to two categories?
:-)- This topic was modified 1 year, 6 months ago by stmichel2.
May 27, 2023 at 3:34 am #1408740Hi stmichel2,
I’m not sure if I fully understand, can you give us more context? also please give us a link on the page mentioned.
Best regards,
NikkoMay 27, 2023 at 5:17 am #1408748i guess he wants to show only posts that are in category a and b – The intersection of the two categories –
only posts that are inside both categories ( a && b)maybe there could be a filter solution in future releases to have a logical relation between the “link” f.e. in:
av_blog blog_type='taxonomy' link='category,4,7' …
this is a multiple selection of two categories but relation is on default an “OR” – maybe a checkbox at that element or as mentioned a filter solution will force an “AND” relation.May 29, 2023 at 1:15 am #1408913Hi stmichel2,
@Guenni007 thanks for the explanation.I think we can use this filter avia_blog_post_query for it. Here’s the code:
add_filter('avia_blog_post_query', 'modify_blog_post_query', 10, 2); function modify_blog_post_query($query, $params) { if ($params['taxonomy'] === 'category' && is_page(10)) { $terms = array(13, 14); $query['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'id', 'terms' => $terms, 'operator' => 'AND' // Include posts in both categories ) ); } return $query; }
just change is_page(10) to the id of the page you want to show and $terms = array(13, 14); replace 13 and 14 to your category.
The code works for any Blog Style except for Grid LayoutBest regards,
NikkoMay 29, 2023 at 8:50 am #1408916Thank you – this works wonderfully – however as you already write not for Gridlayout.
And especially in this context a grid layout would be exactly what is often desired.
So maybe Günter can find in future releases the option to have :
( and on all other elements that have the option to choose Which Entries are displayed? – Select which entries should be displayed by selecting a taxonomy )
May 29, 2023 at 9:20 am #1408917Hi Guenni007,
Thanks for your input.
I have forwarded your request to Günter.Best regards,
NikkoJuly 12, 2023 at 4:55 pm #1413153Hi!
FYI: In 5.6.4 there will be an option: “Multiple Categories/Terms Relation” in various elements.
See https://kriesi.at/support/topic/enfold-upcoming-fixes/
Best regards,
Günter -
AuthorPosts
- You must be logged in to reply to this topic.