- This topic has 10 replies, 3 voices, and was last updated 3 years, 3 months ago by
Fernando.
-
AuthorPosts
-
February 4, 2023 at 10:09 pm #2521775
Jusung
Hello. On my blog page, I want to exclude posts from certain categories.
I used this code as told.
add_action(‘pre_get_posts’, ‘exclude_category_posts’);
function exclude_category_posts( $query ) {
if( $query->is_main_query() && !is_admin() && !is_singular() ) {
$query->set(‘cat’, array( -9, -4, -11, -13, -12 ));
}
}However, when I use this code, it works, but the querry loop pagenation function doesn’t work.
So, the code affect the function of query loop pagenation when it is inherit query from template.I need to use pagenation function, so I turned off the code above.
Is there other way to exclude some cetegories on blog?
February 5, 2023 at 9:05 am #2522287David
StaffCustomer SupportHi there,
is it breaking pagination ? Or is excluding so many posts that pagination is not required ?
February 5, 2023 at 4:33 pm #2522592Jusung
It is breaking.
When I use the code to exclude categoreis on blog, it is breaking the function of pagenation when it is inherit query from template.
If i don’t use inherit query from temlate, it works.
Therefore, right now, i turned off the code to exclude categoreis so that the pagenation of query loop works.
So, I need other way to exclude categories on blog..
February 5, 2023 at 6:37 pm #2522655Fernando Customer Support
Hi Jusung,
Which specific Queryy Loop is it affecting?
The main Query on the link you provided isn’t created with a Query Loop.
Is that the correct page with the issue?
February 5, 2023 at 8:40 pm #2522711Jusung
When I use the code to exlclude categories on blog,
on portfolio page, there is a query loop and I have made pagenation for that. Also, clicked inherit query from template.
on portfolio page, the pagenation of query loop doesn’t work.
Now it is working since I have turned the code off.
February 5, 2023 at 9:09 pm #2522729Fernando Customer Support
How is it specifically breaking the pagination? Where do you want this code to run? Do you want it running on just the Blog page and not other pages like the Porfolio page?
Can you re-add the code so we can see what happens?
February 5, 2023 at 10:37 pm #2522789Jusung
Simply the pagenation is gone.
I need the code to run only on blog.
I will add the code again not and you can see the pagenation is broken.
February 5, 2023 at 10:50 pm #2522794Fernando Customer Support
Can you replace this:
if( $query->is_main_query() && !is_admin() && !is_singular() ) {with this:
if( $query->is_main_query() && !is_admin() && !is_singular() && is_home() ) {in your code?
February 5, 2023 at 11:25 pm #2522809Jusung
I will check it now.
February 5, 2023 at 11:27 pm #2522812Jusung
Yes ! it works now!!
Thank you!!
February 6, 2023 at 12:52 am #2522863Fernando Customer Support
You’re welcome, Jusung!
-
AuthorPosts
- You must be logged in to reply to this topic.