Wow, this is awesome @dmunaretto, thanks for putting this together! Always useful to have some code examples for people to take a look at when starting out.
I thought I’d make a few clarifications about your markup for anyone else that’s looking to use your notes as a jumping-off point. I’m just a beginner with L&L myself, but I figured a second perspective couldn’t hurt.
It seems like this code is trying to use post=current
as if this were a Loop
tag, but post
isn’t a valid attribute of the If
tag (here’s the list of valid attributes). The If
tag compares things based on whatever context you place it in, so if you use it in a loop, it’ll evaluate conditions based on the data from that loop. If it’s just used as-is on a post as you’re doing here, it’ll always evaluate conditions based on the current post it’s placed on. So while this markup seems to work, the post=current
attribute isn’t doing anything.
We’ve already been chatting about this over in this thread but it probably bears repeating here that the correct syntax for this part would be:
<If field=state is value="Illinois">DO THIS.</If>
Yep, this is correct. If anyone wants an explanation of why this is necessary, check out this comment. The tl;dr is that post fields are different than taxonomy fields and are stored in a different part of the WordPress database, so if you want to display some taxonomy fields on a post (or use the If
tag to run some conditional logic on some taxonomy fields as your code shows) you need to tell WordPress where to look to find those fields by using the `Loop’ tag.
The Get
and Set
tags are useful when you want to save data from a loop to be used outside the loop, as you’ve shown.
Thanks again for the thorough write-up, it’s so nice to have people like you in this little community who are willing to put in the effort to make posts like this to help others!