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.