1

This is how to shortcode looks [posts3col ids="249, 318, 93" category="Events"]

And this is some of the code behind it, where I have the problem:

add_shortcode('posts3col', 'posts_func');

function posts_func($atts){
    extract(shortcode_atts(array(
        'ids'=> '',
        'category' => ''        
    ), $atts));

    $options=array(
            'posts_per_page' => 3,
            'category_name' => $category,
            'post__in' => array($ids)
            );
    ob_start(); 
    // run the loop based on the query
    $query = new WP_Query( $options ); .....

The problem I have is with 'post__in', I don't know how to give it the ids. If I write the ids manually in the code like this:

'post__in' => array(249, 318, 93)

it works, but obviously I need to pull the ids from the shortcode I can't insert them manually.

2
  • Can you show us the output of var_dump($ids) ? Commented Jul 25, 2013 at 11:57
  • +1 for including code, it makes life a whole lot easier! Commented Jul 25, 2013 at 15:11

1 Answer 1

2

You need explode to convert string to array.

$options=array(
        'posts_per_page' => 3,
        'category_name' => $category,
        'post__in' => explode(",", $ids);
      );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.