Title: Creating a shortcode to accept multiple IDs
Last modified: August 22, 2016

---

# Creating a shortcode to accept multiple IDs

 *  Resolved [Bloke](https://wordpress.org/support/users/bloke/)
 * (@bloke)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/creating-a-shortcode-to-accept-multiple-ids/)
 * I am developing a shortcode to display a list of products in the accessories 
   category. It works but I am trying to set it up so I can enter the id numbers
   like [my_wpsc_access post__in=”1,2,3,4″]
 *     ```
       add_shortcode('my_wpsc_access', 'my_wpsc_access_shortcode');
       function my_wpsc_access_shortcode($atts) 
   
       {
   
       global $post;
   
       extract(shortcode_atts( array(
   
       	'post_type' => 'wpsc-product',
       	'posts_per_page' => -1,
       	'wpsc_product_category'=>'accessories',
       	'post__in' => array(1,3,),
       	), $atts ) );
   
       	$args = array(
        	'post_type' => $post_type,
       	'posts_per_page'  => $posts_per_page,
       	'wpsc_product_category'=>$accessories,
       	'post__in' => $post_in);
   
       $myquery = new WP_Query($args);
       ```
   
 * That does not work. But if I do this it works.
 *     ```
       $myquery = new WP_Query( array( 'post_type' => 'wpsc-product', 'posts_per_page' => 3, 'wpsc_product_category'=>'accessories', 'post__in' => array(1101,1730,1191,)) );
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [Bloke](https://wordpress.org/support/users/bloke/)
 * (@bloke)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/creating-a-shortcode-to-accept-multiple-ids/#post-5719446)
 * I got it to work using explode.
 *     ```
       add_shortcode('my_wpsc_access', 'my_wpsc_access_shortcode');
       function my_wpsc_access_shortcode($atts) 
   
       {
   
       global $post;
       extract(shortcode_atts( array(
   
       	'post_type' => 'wpsc-product',
       	'posts_per_page' => -1,
       	'wpsc_product_category'=>'accessories',
       	'post__in' => '',
       	), $atts ) );
   
       	$args = array(
        	'post_type' => $post_type,
       	'posts_per_page'  => $posts_per_page,
       	'wpsc_product_category'=>$accessories,
       	'post__in' => explode(',', $post__in),
       	);
   
       $myquery = new WP_Query($args);
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Creating a shortcode to accept multiple IDs’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Bloke](https://wordpress.org/support/users/bloke/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/creating-a-shortcode-to-accept-multiple-ids/#post-5719446)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
