Normally I have the "main-slug"-portfolio view and all posted portfolio items are "online" - a nice function and it works great with the possibility of the custom slug (you see it in action on my page).
Is it possible to filter the categories for this "main" view? I want to hide one category for online view, but I want to see some items of this category in another "special" view online.
Should I do this with "pre_get_posts"? I tried this some month ago and the problem was, that the "filter" in the head of the portfolio view sometimes showed me the "hidden" category.
So what exactly this does only excludes portfolio items which have "my-category-slug". However if an item has two categories assigned: "my-category-slug" and "my-another-category-slug" and you want to show items that have "my-another-category-slug" regardless they have the "excluding" category, then you have to do include all other categories in another query parameter, here is how:
After including the code snippet and adding a new portfolio item in the ""excluded"" category I tested and it works perfect. BUT:
in admin i coud choose the new added ""excluded"" portfolio item in the special internal usage page but if I open the page the added item is not included - I think that your filter works now for all pages and not only for the portfolio archive page. if you want you could test it on my page.
I extended your script with an additional if-condition:
if ( is_post_type_archive ( 'portfolio' ) ) {
YOUR CODE HERE WITHOUT THE return
}
return $query_args;
and now it works perfect - I have now the filtered portfolio items in the main web view and the possibility to show "the hidden portfolio" an other pages for internal use or prrsentations.
Another question about the portfolio:
Normally I have the "main-slug"-portfolio view and all posted portfolio items are "online" - a nice function and it works great with the possibility of the custom slug (you see it in action on my page).
Is it possible to filter the categories for this "main" view? I want to hide one category for online view, but I want to see some items of this category in another "special" view online.
Should I do this with "pre_get_posts"? I tried this some month ago and the problem was, that the "filter" in the head of the portfolio view sometimes showed me the "hidden" category.
I hope I wrote understandable.
Regards André
Hi hahni,
You can apply custom category filtering for portfolio archive with this code:
So what exactly this does only excludes portfolio items which have "my-category-slug". However if an item has two categories assigned: "my-category-slug" and "my-another-category-slug" and you want to show items that have "my-another-category-slug" regardless they have the "excluding" category, then you have to do include all other categories in another query parameter, here is how:
I hope this will help you solve your issue.
Hello Arlind
thanks for your answer but its not the right way:
After including the code snippet and adding a new portfolio item in the ""excluded"" category I tested and it works perfect. BUT:
in admin i coud choose the new added ""excluded"" portfolio item in the special internal usage page but if I open the page the added item is not included - I think that your filter works now for all pages and not only for the portfolio archive page. if you want you could test it on my page.
Good Morning Arlind
I extended your script with an additional if-condition:
if ( is_post_type_archive ( 'portfolio' ) ) {
YOUR CODE HERE WITHOUT THE return
}
return $query_args;
and now it works perfect - I have now the filtered portfolio items in the main web view and the possibility to show "the hidden portfolio" an other pages for internal use or prrsentations.
Thanks a lot