[resolved] Comma Separated Values in a Shortcode Attribute (3 posts)

  1. thobin21
    Posted 6 years ago #

    I am trying to pass comma separated values in a shortcode attribute and having a heck of a time getting it to work.

    The shortcode is: [attachment id="909,908"]

    The code I have so far only pulls the first value:

    function media_library_shortcode($atts) {
    	extract(shortcode_atts(array( 'id' => 1	), $atts));
    	echo '<ul class="attachment_list">';
    	$value = array($id);
    	foreach ($value as $att_id)
    		echo '<li>' . wp_get_attachment_link($att_id) . '</li>';
    	echo '</ul>';
    	add_shortcode('attachment', 'media_library_shortcode');

    Any assistance would be much appreciated.

  2. shazahm1
    Posted 6 years ago #

    I'm pretty much a novice but would you need to explode $id before you iterate thru the foreach?

    Something like:
    $value = explode(',', $id);

  3. thobin21
    Posted 6 years ago #

    @shazahm1, you ROCK! I really appreciate the assistance.

Topic Closed

This topic has been closed to new replies.

About this Topic