Title: Filter in Loop?
Last modified: August 30, 2016

---

# Filter in Loop?

 *  Resolved [flodi](https://wordpress.org/support/users/flodi/)
 * (@flodi)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/filter-in-loop/)
 * I’d like to put a filter on top of this page [http://staging.granapadanocheese.com.cn/ricette/](http://staging.granapadanocheese.com.cn/ricette/)
 * The page show a list of pages and I’d like to let the user filter them by tags.
 * Do you have any idea on how I can do that with your plugin?
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/filter-in-loop/#post-6741974)
 * It’s a bit tricky..
 * To list tags with links to pass the selected tag as a query variable:
 *     ```
       [for each=tag count=10 trim=true]
         <a href="?tag=[each slug]">[each name]</a>,
       [/for]
       ```
   
 * Then, on the same page, to list posts with the passed tag..
 *     ```
       [pass global=query fields=tag]
       [loop type=post tag={TAG}]
         [field title] - [taxonomy tag]
       [/loop]
       [/pass]
       ```
   
 * —
 * The above with list _all posts_ if no tag is selected. To check if any tag was
   passed:
 *     ```
       [if pass={TAG} empty=false]
         ..loop..
       [else]
         No tag selected
       [/if]
       ```
   
 * —
 * To display the term label, inside the [pass] block:
 *     ```
       [for each=tag term={TAG}]Selected tag: [each name][/for]
       ```
   
 *  Thread Starter [flodi](https://wordpress.org/support/users/flodi/)
 * (@flodi)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/filter-in-loop/#post-6742078)
 * As usual your support is stellar!
 * Everything works but the IF to check if no tag is selected.
 * I have this code:
 *     ```
       [for each=tag]
           <div class="onetag"><a href="?tag=[each slug]">[each name]</a></div>
       [/for]
       <div>
       [pass global=query fields=tag]
           [loop type=page fields=url,titolo parent=340 exclude=360 tag={TAG}]
               <a href="{URL}">
               <div class="mitem">
                   <div>{TITOLO}
                       <div><img src="/wp-content/uploads/2015/11/ricetta-hat.png">[if not field="difficolta" value="1"]<img src="/wp-content/uploads/2015/11/ricetta-hat.png">[/if][if field="difficolta" value="3"]<img  src="/wp-content/uploads/2015/11/ricetta-hat.png">[/if]</div>
                   </div>
                   <div>[field image]</div>
                   <div>[for each=tag]<div>[each name]</div>[/for]</div>
                   <div>[ratings] [os_share]</div>
               </div>
               </a>
           [/loop]
       [/pass]
       </div>
       ```
   
 * That works, but does not contains an IF, as you can see because if I try, everything
   seems going bad.
 * I want to show everything in case no tag is selected. If I leave the code as 
   is, and tag is empty, it will get everything?
 *  Thread Starter [flodi](https://wordpress.org/support/users/flodi/)
 * (@flodi)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/filter-in-loop/#post-6742128)
 * Resolved by myself, it worked selecting all if tag empty.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Filter in Loop?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [flodi](https://wordpress.org/support/users/flodi/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/filter-in-loop/#post-6742128)
 * Status: resolved