How to I dynamically output the selected attribute for the HTML Select > Options Tags

I’m having a bit of trouble working out the syntax for doing an inline If statement.

Here is my desired output

<select id="creatives-filter">
  <option value="any">All Creatives</option>
  <option  value="images">Images</option>
  <option **selected** value="elements">Elements</option>
  <option value="words">Words</option>
  <option value="self">Self</option>
  <option value="tastes">Tastes</option>
  <option value="sounds">Sounds</option>
</select>

I want to output selected based on whether the query string is Example Domain

And do so accordingly to all other fields.

This is what I have unsuccessfully tried thus far:

This works.

Images
  <option "{{If check={Get type_query} is value=images }selected{/If}}"  value="images">Images</option>

  <option check="{If check={Get type_query} is value=images }selected{/If}"  value="images">Images</option>

  <option check="{{If check={Get type_query} is value=images }selected{/If}}"  value="images">Images</option>

========

ANy help is truly appreciated.

Hi Mark, I just did some digging through the forum and I found this conversation with @eliot about dynamically adding an HTML attribute. It seems that Eliot suggested a potential syntax, but it doesn’t look like that feature ever got released. I’ve gone ahead and made a feature request for that so feel free to upvote it if you’d like to get notified if/when that feature launches.

1 Like

Thanks Benjamin! I will look.

If you need any volunteer WordPress programmers to work with the roadmap, feel free to let me know. I have signed up for the better. Impressive to see how fast you guys are working on things!

Hey @markofapproval , I’d love to chat about working together on this! I’ll send you a DM.

Hey @markofapproval, it’s been a long time coming but we’ve finally released version 3.0.0 of Loops & Logic, which includes the ability to dynamically add boolean attributes like selected to any tag using the new tag-attributes attribute. I’ve written up a demo of this in use using the example you suggested in this thread, so you can take a look at that in action on the v3.0.0 release blog post. I’m pretty stoked about how that live demo works on the blog post hahaha! Let me know if you have any questions about this :slight_smile:

1 Like