• I’m trying to display a category term only if it has been checked. I’ve tried the following, but it is not working:

    [for each=category]
      [if each=book-review]
        [-if each_value]
           [each link]
        [/-if]
      [/if]
    [/for]

    I’ve tried variation, but none that work including

    • [-if each_value=book-review]
    • [-if each_value=1]
    • [-if each_value=True]

    If I omit [-if each_value] then the term is displayed, but regardless of whether it is checked. Any more suggestions?

    • This topic was modified 4 years, 3 months ago by iantresman.
    • This topic was modified 4 years, 3 months ago by iantresman.
    • This topic was modified 4 years, 3 months ago by iantresman.
    • This topic was modified 4 years, 3 months ago by iantresman.
Viewing 9 replies - 1 through 9 (of 9 total)
  • What if you remove the [-if each-value]-part?

    [for each=category]
      [if each=book-review]
           [each link]
      [/if]
    [/for]
    Thread Starter iantresman

    (@iantresman)

    I tried that, and it displays the term “Book Review” regardless of whether it is checked or not.

    And this?

     [if category=book-review]
          Show what you like or [taxonomy category field=link] to show links to all checked categories.
     [/if]
    Thread Starter iantresman

    (@iantresman)

    Getting closer, but it shows all checked values. I want to show a specific term, only if it is checked. [if each_value] would suggest that this is how to test if a specific term is checked, but I have no idea what “value” a checked term is set to.

    Thread Starter iantresman

    (@iantresman)

    There does not seem to be a way to find whether a term is checked or not. I expected one of the following [if] statements to do so:

    <ul>
    	[taxonomy category]
    	[for each=category ]
    	<li>Term: [each]
    		<ul>
    		<li>Each:  [if each] X       [else] - [/if]</li>
    		<li>Field: [if each_field] X [else] - [/if]</li>
    		<li>Value: [if each_value] X [else] - [/if]</li>
    	 </ul>
    	</li>[/for]
    </ul>

    A clue to the solution is to use “current=true” which looks at the taxonomy applied to the current post, and then only shows checked terms.

    <ul>
    	[taxonomy category]
    	[for each=category ??????????????=????????]
    	<li>Term: [each]
    		<ul>
    		<li>Each:  [if each] X [else] - [/if]</li>
    		<li>Field: [if each_field] X [else] - [/if]</li>
    		<li>Value: [if each_value] X [else] - [/if]</li>
    	 </ul>
    	</li>[/for]
    </ul>
    • This reply was modified 4 years, 3 months ago by iantresman.
    Thread Starter iantresman

    (@iantresman)

    So the solution is as follows:

    [for each=category current=true]
         [if each=book-review][each link][/if]
    [/for]

    But still no idea how to check whether a term is checked or not.

    • This reply was modified 4 years, 3 months ago by iantresman.

    But still no idea how to check whether a term is checked or not.

    Not sure what you mean with “is checked”. Do you want to know how many terms have a post assigned? Or the terms of the current post?

    Thread Starter iantresman

    (@iantresman)

    My post has three available terms in a category:
    [ ] Book Review
    [ ] Free Content
    [ ] Uncategorised

    I can check and hence select any of the terms, eg:
    [X] Book Review
    [ ] Free Content
    [ ] Uncategorised

    In a post, I might want to display “Book review” (if it is checked), and either “Free” or “Premium” depending on whether “Free Content” is checked.

    In this case you should look into the content section of the documentation and use [taxonomy]

    Use taxonomy to loop throught the category you like and for/each to get the content you like.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show category term if checked’ is closed to new replies.