Keyword

Echo One Value from Extra Field Multi-Select (Randomly)

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148244 by Joe Campbell
What code would I use to echo one value from a extra field multi-select?

When I echo the extra field, it renders each selected value comma separated.
<?php echo $item->extraFields->MultiSelectAlias->value; ?>

I only want to echo one of the selections (randomly)

Please Log in or Create an account to join the conversation.

More
8 years 6 months ago #148245 by Tassos Marinos
Replied by Tassos Marinos on topic Echo One Value from Extra Field Multi-Select (Randomly)
Hey Joe,

Try the following code:
$valuesArray = explode(",", $this->item->extraFields->MultiSelectAlias->value);

shuffle($valuesArray);

$randomValue = $valuesArray[0];

echo $randomValue;

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148249 by Joe Campbell
Thanks Tassos - It Works :)

Please Log in or Create an account to join the conversation.

More
8 years 6 months ago #148253 by Tassos Marinos
Replied by Tassos Marinos on topic Echo One Value from Extra Field Multi-Select (Randomly)
I am glad I could help you Joe!

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum