Title: Using Conditional Statements
Last modified: August 21, 2016

---

# Using Conditional Statements

 *  Resolved [psperkins](https://wordpress.org/support/users/psperkins/)
 * (@psperkins)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-conditional-statements/)
 * Is it possible to use nested conditionals within the loop shortcode?
 * I’d like to use in_category or has_term to segment my loops.
 * Great plugin btw, thanks for your work on this.
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

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

 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-conditional-statements/#post-5062839)
 * Hello,
 * There’s an `[if]` shortcode for simple conditionals (no post found, first/last
   post, every X posts). I can imagine some parameters could be added to further
   filter the loop.. Do you mean something like this?
 *     ```
       [loop type="post"]
           [content field="title"]
           [if in_category="cat1, cat5, cat7"]
               Display something
           [/if]
           [if taxonomy="status" has_term="discount"]
               On sale!
           [/if]
       [/loop]
       ```
   
 * However, an inherent limitation of shortcodes is that they can’t be nested within
   itself, so `[if]` cannot be inside another `[if]`.
 * For complex queries, you may need to break it up into several loops, or write
   it in PHP – although it would be nice to find an elegant solution.
 *  Thread Starter [psperkins](https://wordpress.org/support/users/psperkins/)
 * (@psperkins)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-conditional-statements/#post-5062870)
 * Yeah I was basically looking for a condition such is ‘in_category’ to show a 
   call to action if the post in the loop has a specific category.
 * I can do this easily in PHP but was just wondering if this could also be accomplished
   in a shortcode – I have found your plugin is especially useful in Genesis themes–
   I don’t use them all that often but when I do this plugin has become a go-to 
   solution that is much simpler than creating multiple templates or loop functions.
 * I hadn’t given any thought to nested ‘if’ statements in shortcodes so that’s 
   useful new information for me.
 * Thanks for your answer, I appreciate it.
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-conditional-statements/#post-5062937)
 * Hello,
 * I added a few parameters to the `[if]` shortcode to filter by category or taxonomy
   term. Please see the latest update.
 * The parameters are used like this:
 *     ```
       [loop type="post"]
           [content field="title"]
           [if category="cat1, cat5, cat7"]
               Display something
           [/if]
           [if taxonomy="status" term="discount"]
               On sale!
           [/if]
           [if not taxonomy="status" term="discount"]
               Regular price
           [/if]
       [/loop]
       ```
   
 * Hopefully that will add more flexibility to the loop. I appreciate the suggestion!
 *  Thread Starter [psperkins](https://wordpress.org/support/users/psperkins/)
 * (@psperkins)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-conditional-statements/#post-5062944)
 * This works like a charm. Thank you!

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

The topic ‘Using Conditional Statements’ 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/)

 * 4 replies
 * 2 participants
 * Last reply from: [psperkins](https://wordpress.org/support/users/psperkins/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/using-conditional-statements/#post-5062944)
 * Status: resolved