• Resolved Bloke

    (@bloke)


    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

    (@bloke)

    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.