Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to create a shortcode with an array as input like so

function product_gallery_shortcode($atts) {

extract(shortcode_atts(array(
            'product_id' => '31',
            'prodvid' => false,
            'youtubeids'=>'',//['lbRqMddP2jo','eFAxx817rC0'],
            'thumbnr' =>2
                ), $atts));

I like to loop throught the youtube id's but i don't know how to initialize the youtubeids as an array

so it reads

    'youtubeids'=> array('lbRrePOP2jo','eFAxx17rC0'),

regards

share|improve this question
2  
I'm sorry, but I don't understand what you goal is. Could you elaborate? Currently the variable $youtubeids holds that array... –  kaiser Mar 5 '13 at 11:49
    
@kaiser, well when i use the shortcode the values i passes into youtubeids didn't work as an array in my shortcode function. So i had to turn the values into an array again, see my answer –  alex Mar 5 '13 at 12:16

2 Answers 2

Ok found a solution

function product_gallery_shortcode($atts) {
extract(shortcode_atts(array(
            'product_id' => '31',
            'prodvid' => false,
            'youtubeids'=> '',
            'thumbnr' =>2
                ), $atts));
etc

and i had to turn youtubeids into an array again

$youtubeidsnew = array();
$youtubeidsnew = explode(',', $youtubeids);
share|improve this answer
2  
It is not clear how this 'fixes' your problem ( or what your problem actually was ). Could you ellaborate so that this answer may be helpful to other people? –  Tom J Nowell Mar 5 '13 at 12:15
    
As you goal is completely unclear (what is the expected output?), it's impossible to understand your "solution". I'm holding back from a downvote, but please elaborate your goal better (edit question) and then elaborate why this is a fix. –  kaiser Mar 5 '13 at 12:21

Could you not just do:

extract(shortcode_atts(array(
            'product_id' => '31',
            'prodvid' => false,
            'youtubeids'=>array('lbRrePOP2jo','eFAxx17rC0'),
            'thumbnr' =>2
        ), $atts));
share|improve this answer
    
yes that what i did staticly but the shortcode looks something like this: [productgallery product_id="7" prodvid="yes" youtubeids="lbRfgPOP2jo,eFAEfg7rC0" thumbnr="2"] –  alex Mar 5 '13 at 12:12
1  
I'm sorry but there simply isn't enough information to answer then. It's not clear what your problem is, or what an answer would be. We'd need code –  Tom J Nowell Mar 5 '13 at 12:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.