Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Adding an array parameter to a Wordpress shortcode / PHP script

Avatar of Blair Benjamin
Blair BenjaminFlag for United States of America asked on
7 Comments1 Solution1609 ViewsLast Modified:
Hello,  I have a custom shortcode that calls an API.  Works great, but I'd like to add a parameter to it in order to tweak the output a bit.  We already have one paramter, but the second one I'd like to add would be more along the lines of an array, so I need some tips.   The shortcode calls an API that pulls events from a calendar database.   Below are the lines of code related to this (not the full script of course):
function cal_events_shortcode($params = array()) 
extract(shortcode_atts(array("limit" => 5), $params));
$eventTypes = array (3,7);

This shortcode is called by inserting  [cal_events limit="4"] into a Wordpress page.   If no value is passed for "limit", it defaults to 5.  It then pulls events with the event types of 3 and 7, based on the hard-coded value for "eventTypes".

What I want to do is accept the values of "3, 7" as variables that are passed by the shortcode call and then inserted into the $eventTypes variable.    So, what would the "extract(shortcode_atts..." line of code look like if also accepting the values that need to go into $eventTypes array?

I imagine this is pretty simple, but I don't call myself a programmer.

Thanks for any tips!