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!
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros