We're merging with GenerateBlocks! Learn more here.

[Support request] Exclude Post by Taxonomy (category or tag)

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Exclude Post by Taxonomy (category or tag)

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28864
    TWarrior
    Participant

    We have a News website. With a big volume of dayly posts publications.

    Some news (posts) are tagged as “Featured” or “Important”, in order to show them in Homepage. For this, we have a WPShowPost list which shows only the News (posts) tagged as “Featured”

    Below, We want to show, with another WPShopost list, the rest of the News (posts) that are not tagged as “Featured”.

    But currently, it seems that WP Show Post only allows to exclude Posts by ID (not exclude by category or tag)

    So, How can We do this?

    Thanks.

    #28886
    elvin
    Moderator

    Hi there,

    There are 2 ways of doing this. In both, we need to use a PHP snippet.

    One is to include only the things you want by filtering it.

    Example:

    add_filter('wpsp_query_args',function( $args, $settings ){
    	if ( 1699 === (int) $settings['list_id'] ) {
    		$args['tax_query'] = array(
    			'relation' => 'OR',
    			array(
    				'taxonomy' => 'category',
    				'field'    => 'slug',
    				'terms'    => array( 'campaigns','project-updates' ),
    			),
    			array(
    				'taxonomy' => 'post_tag',
    				'field'    => 'slug',
    				'terms'    => array( 'sample-tag-1' ),
    			),
        	);
        }
    	return $args;
    },10,2);

    Just make sure you change the values.

    Replace 1699 with the ID of your WPSP list. Replace ‘campaigns’ and ‘project-updates’ with your category slugs and replace ‘sample-tag-1’ with your tag slug.

    Another way is by actual exclusion:

    Example.

    add_filter( 'wpsp_query_args', function( $args, $settings ) {
        if ( 1821 === (int) $settings['list_id'] ) {
    		$args['category__not_in'] = array(1,8,49);
    		$args['tag__not_in'] = array(38);
    		
            var_dump($args);
        }
    
        return $args;
    }, 10, 2 );

    Replace 1699 with the ID of your WPSP list.

    #28902
    TWarrior
    Participant

    thank, I will try them

    #28915
    elvin
    Moderator

    Note: If that doesn’t work, you may have to update to this version:
    https://wpshowposts.com/wp-show-posts-1-2-0/

    Or try Tom’s suggestion here which is the shortcode args filter way.
    https://wpshowposts.com/support/topic/including-more-than-one-post-type/#post-13241

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