• Resolved wpress2010

    (@wpress2010)


    I have a set of conditional statements in a template. In this example, there is a Pod field called Agent, and it is populated by a dropdown that contains single individual names in the format “John Smith” (no quote marks), and a couple of choices that are combinations of two names, such as “John Smith and Bob Black”.

    My [if] statements work fine when any single name is selected from the dropdown. But when a dropdown choice contains two names in the format “John Jones and Bob Black”, the [if] statement fails to work. Here’s an example:

    [if agent=”John Smith”]
    <p class=”j_button”>Email John</p>
    <p>Call John: 555-555-5555</p>
    [/if]
    [if agent=”Jane Jones”]
    <p class=”j_button”>Email Jane</p>
    <p>Call Jane: 555-555-5555</p>
    [/if]
    [if agent=”Bob Black”]
    <p class=”j_button”>Email Bob</p>
    <p>Call Bob: 585-259-9139</p>
    [/if]
    [if agent=”John Smith and Bob Black”]
    <p class=”j_button”>Email Bob</p>
    <p>Call Bob: 555-555-5555</p>
    [/if]

    A look at the Pod item itself shows that the Agent: field says (no quotes) “John Smith and Bob Black”

    Yet the conditional stuff on the 4th [if] conditional doesn’t show, presumably because that compound Agent: field is not seen as a plain string by the template.
    The first three [if] conditionals work fine.

    What am I getting wrong?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    [if][/if] doesn’t work in the way you’ve described above. It’s not matching the actual values in the field, it doesn’t have that capability and is not programmed to do any kind of equality validation. The functionality of the [if field] is to only determine if the field has a value or is empty.

    If it worked in anyway to the way you’ve described above, that is purely coincidental and isn’t supported in the way the [if] template tag is defined at the moment.

    I’m not exactly sure what you’re attempting to do with that style of conditional checking, but it would be better handled by using a Relationship field to a Custom Post Type where your Agents and their phone numbers were stored, then you could just link to their content through the relationship field.

    • This reply was modified 5 years, 11 months ago by Jim True.
    Thread Starter wpress2010

    (@wpress2010)

    Thanks, Jim. Actually, it works perfectly now – it was just that this is for a heavily cached site, and I forgot to clear all of the page and Pods elements caches.

    I dunno about the functionality of the [if] field. I did read that it only supports whether a field has a value or not. But for me, it WILL match any string and perform the conditional action, at least in this context. It is repeatable over several different templates I wrote.

    All I am trying to do is have the code spit out some different info depending on the value of a dropdown that has been selected in a Pod.

    • This reply was modified 5 years, 11 months ago by wpress2010.
    Plugin Contributor Jim True

    (@jimtrue)

    I totally get that’s what you’re attempting to do, but you’re using it at present to maintain phone numbers, emails, etc. That’s very unsupportable should someone take over your project at some point. You’ve hard-coded emails into a Pods Templates. Does that make sense in the long run? When you add a new person, not only do you have to go into the field and add them to your Simple Custom Defined List for ‘Agent’ but you also have to add all their details to your Pods Template. Every time they change their phone number, etc. you have to find them in the Pods Template.

    What if you suddenly needed to output a page with all agents and contact details? You can’t use the one Pods Template you’re doing above because it’s a completely different layout.

    Your Agents should be a Custom Post Type and connect them to other parts of your site with a relationship field to agents. That’s just smarter, more user friendly and more usable in the long run. Please watch the video I linked; we show this. It takes minutes to setup.

    The fact that what you have setup works for you, honestly, is just surprising; unfortunately, that kind of functionality cannot be guaranteed to work in the future, because that’s not in the scope of the current implementation. When we replace this, it will be handled using Twig/Timber Templating more than likely.

    Thread Starter wpress2010

    (@wpress2010)

    Thank you for this. It’s kind of an unusual site, and this Pods implementation is just a kind of “placeholder” to keep them going until a major IDX (real estate) database integration takes place. They’ll never have more than 4 or 5 agents, so for now, it works well enough.

    The reason I used the Pods system is that I found I could easily design an interface that they could use to update their property listings without knowing anything about WordPress, and without being able to seriously wreck anything important.

    I think I will look at that video and change the Pods setup in the interim, as the IDX thing is not in my bailiwick, and therefore I don’t have to worry about its timetable for installation.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Template tag question’ is closed to new replies.