Viewing 15 posts - 1 through 15 (of 20 total)
  • Posted in: Clique
  • #217614
    krabban333
    Member
    Post count: 21

    How do I exclude a category from showing in the portfolio?
    I’ve tried changing stuff around in the WP_Query, but I can’t seem to get the regular category exclude to work.

    Here’s the query:
    // PORTFOLIO QUERY SETUP
    global $post, $wp_query;
    $portfolio_args=array(
    ‘post_type’ => ‘portfolio’,
    ‘post_status’ => ‘publish’,
    ‘paged’ => $page,
    ‘portfolio-category’ => $category_slug,
    ‘posts_per_page’ => $item_count
    );
    $portfolio_items = new WP_Query( $portfolio_args )

    Any tips?
    Thanks!

    #217623
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Not 100% sure it will work, give a try just add your Portfolio category slugs that you want to exclude in this line.
    'terms' => array( 'cat-name' ),

    Copy this code below to your functions.php

    function search_filter_get_posts($query) {
        if ( !$query->is_search )
            return $query;
    
        $taxquery = array(
            array(
                'taxonomy' => 'portfolio-category',
                'field' => 'slug',
                'terms' => array( 'cat-name' ),
                'operator'=> 'NOT IN'
            )
        );
    
        $query->set( 'tax_query', $taxquery );
    
    }
    add_action( 'pre_get_posts', 'search_filter_get_posts' );

    Let us know the result.

    -Rui

    #217637
    krabban333
    Member
    Post count: 21

    Works like a charm! Thanks!

    #217639
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Great. I’m always afraid of that filter 🙂

    -Rui

    #295536
    theFencer
    Member
    Post count: 27

    It doesn’t work for me!
    I created a child theme and added that function to the newly created functions.php

    Is it correct?

    #295549
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    @theFencer

    Yes, it’s suppose to.
    Can you provide me admin credentials to have a look at your functions.php of the child theme?

    -Rui

    #295551
    theFencer
    Member
    Post count: 27
    This reply has been marked as private.
    #295763
    theFencer
    Member
    Post count: 27
    This reply has been marked as private.
    #295765
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    @theFencer thanks
    Looking at your code I can confirm that the slug hall-of-fame doesn’t exist has a portfolio category.

    https://www.dropbox.com/s/93yh6uv3jeder5d/Screenshot%202016-10-11%2014.23.43.png?dl=0

    What are you trying to achieve exactly?

    -Rui

    #295772
    theFencer
    Member
    Post count: 27

    Well, I just wanted to exclude the articles of category hall-of-fame from the blog (menu: news).
    Viceversa, I want to leave these articles in the hall of fame menu page.

    Perhaps the attached screenshots explain better than words…

    Attachments:
    You must be logged in to view attached files.
    #295780
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    ok, the code I provide was to exclude portfolio categories that’s the difference.

    I already changed this line of code
    'taxonomy' => 'portfolio-category',
    to this one
    'taxonomy' => 'category',

    Check if it works.

    -Rui

    #295784
    theFencer
    Member
    Post count: 27

    Strangely it doesn’t (the article is still visible in both pages).
    Should I put this filter somewhere?

    #296022
    theFencer
    Member
    Post count: 27

    Hi Rui, do you have news for me?

    #296234
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Will need ftp to try some things.
    can you send it in a private reply.

    -Rui

    #296249
    theFencer
    Member
    Post count: 27
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register