• Resolved joropress

    (@joropress)


    I’d like to exclude some categories from showing on the items-list. How could I do that and is there a way to show the featured ad option in the quick edit menu?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, you should be able to do that by adding the below code to your theme functions.php file

    
    add_filter( "adverts_list_query", "exclude_advert_categories" );
    function exclude_advert_categories( $args ) {
        if( is_page( adverts_config( 'config.ads_list_id' ) ) ) {
            $args["tax_query"] = array();
            $args["tax_query"][] = array(
                'taxonomy' => 'advert_category',
                'field'    => 'term_id',
                'terms'    => array( 103, 115, 206 ),
                'operator' => 'NOT IN',
            );
        }
    
        return $args;
    }
    

    where 103, 115, 206 are IDs of categories you want to exclude.

    Thread Starter joropress

    (@joropress)

    Thanks for your fast reply!
    I have put the code in my function.php file (changing the IDs to suit my needs) but it continues showing all categories on the items-list with no exclusion. Perhaps the problem is somewhere in the way I use the code to show the categories? I put this in my list-item.php file (yes, I know it’s a bad practice, because of the updates…), but I don’t know how to do it in another way.

    
    <span class="category-label">
       <?php $advert_category = get_the_terms( get_the_ID(), 'advert_category' ) ?>
       <?php foreach($advert_category as $c): ?> 
       <a href="<?php esc_attr_e( get_term_link( $c ) ) ?>">
       <?php echo join( " / ", advert_category_path( $c ) ) ?></a>
       <?php endforeach; ?>
    </span>
    
    Thread Starter joropress

    (@joropress)

    My fault! Your solution perfectly works on the live server, but now I realize that it hides not only the category label, but all the ads added to this category. Actually need to hide/exclude only the category name/label from showing on the item-list. It would be even better if I can hide/exclude it from showing everywhere, but most important is to hide it from the items-list.
    Thanks again for the fast replay and in advance for my last question!

    Plugin Author Greg Winiarski

    (@gwin)

    Modifying template files is ok as long as you remember to create a child template file and make the changes there, how to create a child template you can learn here https://wpadverts.com/documentation/child-themes-and-templates/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude category from ad display’ is closed to new replies.