- This topic has 7 replies, 2 voices, and was last updated 6 months, 2 weeks ago by
Leo.
-
AuthorPosts
-
August 17, 2020 at 8:57 am #1406479
alexis
Hello, I added this in the functions file :
add_action( 'pre_get_posts', function( $query ) { if ( $query->is_main_query() ) { $query->set( 'cat', -5 ); } } );
But it changes my back office dasboard. Articles don’t appear anymore. How can I do that?
On my Blog page I want to display only certain categories
Alexis
agency K-LYAAugust 17, 2020 at 10:32 am #1406595Leo
StaffCustomer SupportHi there,
Where are you adding the code?
In the child theme’s
function.php
?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 17, 2020 at 11:00 am #1406652alexis
Yes
Alexis
agency K-LYAAugust 17, 2020 at 1:37 pm #1406832Leo
StaffCustomer SupportCan you try this code instead?
https://docs.generatepress.com/article/exclude-categories-from-posts-page/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 17, 2020 at 11:52 pm #1407199alexis
I already had this function
add_filter('pre_get_posts', 'excludeCat'); function excludeCat($query) { if ( $query->is_home ) { $query->set('cat', '-5'); } return $query; };
I put them back => disabled because on this page https://ac9a-86a90d6267d0.wptiger.fr/lm-wedding-planner it removes the related post. I had added the following function also for related posts (which worked very well) :
add_filter( 'get_next_post_excluded_terms', 'tu_exclude_terms' ); add_filter( 'get_previous_post_excluded_terms', 'tu_exclude_terms' ); function tu_exclude_terms() { if ( has_category( 4 ) ) { return array( 5 ); } elseif ( has_category( 5 ) ) { return array( 4 ); } };
In fact, I wish that on my Blog page there are only the articles of “x” category. When you click on these posts you will find related posts from the same category at the bottom.
On my Achievements page, inside a post in this category there are only related posts from the same category.
The function I set up worked fine but just disabled my dashboard display of the posts
Alexis
agency K-LYAAugust 18, 2020 at 8:28 am #1407974Leo
StaffCustomer SupportIn fact, I wish that on my Blog page there are only the articles of โxโ category.
That case wouldn’t it be better if you just use the category archive instead of the main posts page?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 18, 2020 at 10:44 am #1408159alexis
I created a page with WP Show Posts and it works. Thanks
Alexis
agency K-LYAAugust 18, 2020 at 1:14 pm #1408368Leo
StaffCustomer SupportNo problem ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.