Okay
  Print

How to Restrict or Exclude Terms / How to Restrict or Exclude Terms and their post?

I am adding an example to help you understand how term restriction works,

For the example: i have three product category terms,

i) Clothing

ii) Music

iii) Poster

and 6 products where,

product #1, has Clothing and Poster

product #2, has Music

product #3, has Poster

product #4, has Clothing

product #5, has Music & Poster

product #6, has Clothing & Music

Step 1, Now in the builder, if you restrict the term Music, (***IMPORTANT)

In your search page you will get the below two option for searching,

i) Clothing

ii) Poster

Step 2, Now you have to choose the pre query taxonomy in the Global Settings, in the pre query taxonomy you have to select the other two terms that is in my example Clothing and Poster. (***IMPORTANT)

so you will get the result like below,

product #1, product #3, product #4, product #5, product #6,

now you may have a questions why you will get the result

product #5, has Music & Poster

product #6, has Clothing & Music

as i have restricted the terms Music, this is because though you have restricted the term Music but if you look closely the product #5 & #6 have other two terms Poster and Clothing, that's why they may show in you search result, but product #2 will never appear in the frontend.

NB: this feature is currently on experimental phase and needs more testing and research, as today may 24, 2018 one of our user inform us that, the restricted post may still appear based on your other filtering criteria for example meta data.

If you want to restrict specific post id then you can do it using our grid template easily, just check the post id that you don't want to show in the grid template like below simple grid template,

<div class="reactive-container-fluid">  <# if(data.view == 'list') { #>  <div class="reactive-row reactiveGridBlock {{ data.listClass }}">    <# } else { #>    <div class="reactive-row reactiveGridBlock">      <# } #>      <# _.each(data.posts, function( post ) { #>      <# if(["12", "15", "16", "65"].indexOf(post.ID) == -1) { #>        <!-- Grid -->        <# if(data.view == 'list') { #>          <div key=src={{ post.ID }} data-uid={{ post.ID }} class="{{data.listColumnClass}} reativeinfoWindowPopUp reactiveGridType-Simple fadeIn" data-wow-duration=".5s" data-wow-delay={{ post.delay}} >        <# } else { #>          <div key=src={{ post.ID }} data-uid={{ post.ID }} class="{{data.columnClass}} reativeinfoWindowPopUp reactiveGridType-Simple fadeIn" data-wow-duration=".5s" data-wow-delay={{ post.delay}} >        <# } #>          <div class="reactiveGridImage">            <a href="{{ post.post_link }}" class="overlay"></a>                    <# if(post.thumb_url) { #>                      <img src={{ post.thumb_url }} alt="Image">                    <# } else {#>                      <img src={{ data.gridPlaceHolder }} alt="Image">                    <# } #>              <h3 class="reactiveTitle">{{ post.post_title }}</h3>            <span class="reactiveDate">{{post.post_formated_date}}</span>         </div>        </div>        <!-- Grid End -->     <# } #>    <# }) #>   </div>
</div>

after the post loop you can see that we have added the below line

<# if(["12", "15", "16", "65"].indexOf(post.ID) == -1) { #>

here in the array we have kept some post id ["12", "15", "16", "65"] which we don't want to show in the grid.

same goes for if you want to restrict some post based on some terms and here's the code,

<div class="reactive-container-fluid">  <# if(data.view == 'list') { #>  <div class="reactive-row reactiveGridBlock {{ data.listClass }}">    <# } else { #>    <div class="reactive-row reactiveGridBlock">      <# } #>      <# _.each(data.posts, function( post ) { #>
      <# var restrict_post = false;          _.each(post.terms.product_cat, function(term) {          if(["clothing", "brand", "hoodie", "t-shirt"].indexOf(term.slug) != -1) {              restrict_post = true;          }        })        if(!restrict_post) {         #>        <!-- Grid -->        <# if(data.view == 'list') { #>          <div key=src={{ post.ID }} data-uid={{ post.ID }} class="{{data.listColumnClass}} reativeinfoWindowPopUp reactiveGridType-Simple fadeIn" data-wow-duration=".5s" data-wow-delay={{ post.delay}} >        <# } else { #>          <div key=src={{ post.ID }} data-uid={{ post.ID }} class="{{data.columnClass}} reativeinfoWindowPopUp reactiveGridType-Simple fadeIn" data-wow-duration=".5s" data-wow-delay={{ post.delay}} >        <# } #>          <div class="reactiveGridImage">            <a href="{{ post.post_link }}" class="overlay"></a>                    <# if(post.thumb_url) { #>                      <img src={{ post.thumb_url }} alt="Image">                    <# } else {#>                      <img src={{ data.gridPlaceHolder }} alt="Image">                    <# } #>              <h3 class="reactiveTitle">{{ post.post_title }}</h3>            <span class="reactiveDate">{{post.post_formated_date}}</span>         </div>        </div>        <!-- Grid End -->     <# } #>    <# }) #>   </div>
</div>

here ["clothing", "brand", "hoodie", "t-shirt"] are the terms that you want to restrict the post if the post have any of this terms

if(["clothing", "brand", "hoodie", "t-shirt"].indexOf(term.slug) != -1) {

In the above example we have only show this example with productcat which is a woocommerce category taxonomy but you can use any custom taxonomy if you want, all you have to do is to change your taxonomy name, instead of product_cat

<# var restrict_post = false;
_.each(post.terms.your_taxonomy_name, function(term) {
if(["clothing", "brand", "hoodie", "t-shirt"].indexOf(term.slug) != -1) {
restrict_post = true;
}
})
if(!restrict_post) {
#>

make sure you close the if bracket before the for loop as we have done after the <!-- Grid End --> comment

<!-- Grid End -->
<# } #>

I hope this explanation will help you how term restriction or term excluding works with their post.

NB: if you use exclude posts, the number of posts in the bar block will not work as the number of posts, Pagination will always show the actual number of posts so if you want you can calculate the number of posts in the grid template and show it above the grid using the below code paste it before your grid template begins, As for pagination just use 'Load More' instead.

<# var post_count = 0;
_.each(data.posts, function( post ) {
var restrict_post = false;
_.each(post.terms.your_taxonomy_name, function(term) {
if(["clothing", "brand", "hoodie", "t-shirt"].indexOf(term.slug) != -1) {  restrict_post = true; }
})
if(!restrict_post) {      post_count = post_count + 1;       }
})
#>
<div>{{post_count}}</div>