WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple custom shortcode plugin where you give it a tag and it'll display the titles of all the posts with that tag.

e.g. In my post if I type "[listposts tag=oct-2011]" it will output the titles of all posts tagged as "oct-2011".

This plugin has been working fine for me until the v3.2 upgrade.

Now, it still works fine when the post which uses the shortcode is viewed on its own. But when that post is viewed on the homepage, the get_posts() query returns 0 results.

What do I need to do to fix the plugin?

Here is the relevant code:

function listposts($atts) {
    $atts = shortcode_atts(
            'tag' = 'jan-2011',
            'numberposts' = '-1',
            'orderby' = 'post_date',
            'order' = 'asc',
            'post_status' = 'any' ),

    $catposts = get_posts($atts);
    $out = '';
    foreach ($catposts as $single) {
        $out .= $single->post_title;

    return $out;
share|improve this question
Edit:- Please change 'numberposts' to 'posts_per_page'. – Rutwick Gangurde Oct 4 '11 at 4:01

The get_posts() argument is supposed to be numberposts not posts_per_page and you were passing it as string. Try making it an integer.

function listposts( $atts ) {

    $atts       = shortcode_atts( array( 
        'tag'         => 'jan-2011',
        'numberposts' => -1,
        'orderby'     => 'post_date',
        'order'       => 'asc',
        'post_status' => 'any' 
    ), $atts );
    $catposts   = get_posts( $atts );
    $out        = '';

    foreach( $catposts as $single ) {
        $out .= "{$single->post_title}<br />";

    return $out;
add_shortcode( 'list', 'listposts' );
share|improve this answer

I checked your code locally, it works fine...

function listposts($atts) {
    $atts = shortcode_atts(array('tag' => 'lorem', 'posts_per_page' => -1, 'orderby' =>  'post_date', 'order' => 'asc', 'post_status' => 'any'), $atts);
    $catposts = get_posts($atts);
    $out = '';
    foreach ($catposts as $single) 
            $out .= $single->post_title."<br />";
    return $out;

    add_shortcode('list', 'listposts');

Please recheck if you're entering the shortcode in the visual editor's HTML mode.

share|improve this answer
Hey Rutwick. Thanks for responding. I tried changing numberposts to posts_per_page but still no dice. I don't think I'm doing anything wrong with the shortcode because it works fine when I view the post as a single page. The get_posts function only returns a null set when the post with the shortcode is viewed within the homepage. I guess it might be a conflict with my specific setup (multisite)? – markamgine Oct 11 '11 at 18:58

Your Answer


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.