WordPress.org

Ready to get started?Download WordPress

Forums

query_posts by tag and showposts (5 posts)

  1. evaneckard
    Member
    Posted 2 years ago #

    I can't seem to get this to work (even though it seems like it should from the codex).

    <?php if (have_posts()) : ?>
    <?php query_posts("showposts=4&tag=featured"); ?>
    <?php while (have_posts()) : the_post();?>

    Any ideas?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    what is it doing or not doing?

    is there more code to it?

    you could paste the whole code of the template (or whatever you are working on) into a http://pastebin.com/ and post the link to it here.

  3. evaneckard
    Member
    Posted 2 years ago #

    I was simply trying to open the loop showing only 4 posts tagged with "featured"

    If I use just showposts=4, the loops shows the most current 4 posts. If I use just the tag, nothing shows even though I have posts tagged as such.

    Looking at the codex, it seems it should work.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('posts_per_page=4&tag=featured&paged=. $paged); ?>
  5. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    you could try a variation:

    <?php $args = array(
    'posts_per_page' => 4,
    'tag_slug__in' => array('featured')
    );
    query_posts( $args ); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post();?>

    http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

    or check the spelling; or try and use the tag ID ...

Topic Closed

This topic has been closed to new replies.

About this Topic