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 plugin request that I cannot find by a Google search because I can't think of what it would be called:

I need a plugin that will, on a page-by-page basis, allow me to define a list of tags (probably via a Custom Field), and should show the most recent 5 (or any number) posts that have that tag on the bottom of the page.


share|improve this question
up vote 1 down vote accepted

Here's a quick shortcode I put together for your functions.php file if you want to use it as a starting point. or it can be converted to a plugin if you prefer.

function wpse27961_show_tagged_posts( $atts ) {
    extract( shortcode_atts( array(
        'tags' => '',
        'number' => 5,
    ), $atts ) );

    $args = array(
        'posts_per_page' => $number,
        'tag' => $tags

    $wpse_tagged_posts = new WP_Query( $args );

    $output = "";

        $output .= "<ul>";
            $output .= '<li><a href="';
            $output .= get_permalink();
            $output .= '">';
            $output .= the_title( '', '', false );
            $output .= '</a></li>';
        $output .= "</ul>";


    return $output;
add_shortcode( 'wpse_tagged_posts', 'wpse27961_show_tagged_posts' );

yeah, it's not pretty, but someone can tweak it if they have the time. add the shortcode to your page like this:

[wpse_tagged_posts tags="foo,bar"]

it'll default to showing 5 posts. or if you want a specific number of posts:

[wpse_tagged_posts tags="foo,bar" number="6"]
share|improve this answer
That is great! May I suggest one thing - add a wp_reset_query(); after the "endif;" so the "edit" link that appears on pages when you're logged in works correctly. – GavinR Sep 9 '11 at 0:59
Thanks, updated. – Milo Sep 9 '11 at 1:24

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.