Can't really get the hang of this. I'm trying to make a wordpress shortcode that gets values from an array in another file. What I'm trying to achieve is to make the shortcode 'myshortCode valueFromKey' work depending on the key.
This is my shortcode function in functions.php
function someCode($opts) {
require_once( get_stylesheet_directory() . '/assets/php/array.php' );
return $array[$opts[0]];
}add_shortcode('myshortCode', 'someCode');
And this is the array in array.php
$array = array(
'key1' => 'a string respons...',
'key2' => '...from external API'
);
But no matter what I do I can only get the first key value from the array. e.g.
'myshortCode key1'
'myshortCode key2'
only returns 'myshortCode key1'
I plan on using this to display respons data from an external API. So all of these shortcodes will be in different sections on the same page.