Site logo

[Resolved] exclude categories on Blog.

Home Forums Support [Resolved] exclude categories on Blog.

Home Forums Support exclude categories on Blog.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #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?

    #2522287
    David
    Staff
    Customer Support

    Hi there,

    is it breaking pagination ? Or is excluding so many posts that pagination is not required ?

    #2522592
    Jusung

    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..

    #2522655
    Fernando
    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?

    #2522711
    Jusung

    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.

    #2522729
    Fernando
    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?

    #2522789
    Jusung

    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.

    #2522794
    Fernando
    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?

    #2522809
    Jusung

    I will check it now.

    #2522812
    Jusung

    Yes ! it works now!!

    Thank you!!

    #2522863
    Fernando
    Customer Support

    You’re welcome, Jusung!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.