Support » Fixing WordPress » post filtering/selection.

  • After searching trough the forum and the various questions/answers i thought this would help me w/my post selection issue.

    <ul>
    <?php query_posts('cat=seasonal&showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    I have two, out of six posts with a category of “seasonal” however the code above…that should work. Doesn’t. it brings in all the posts.
    What am I doing wrong please?
    Thank you
    D

Viewing 4 replies - 1 through 4 (of 4 total)
  • The “cat” parameter is looking for a category ID or term_id. To use the category slug it should be category_name=seasonal.

    Rather than using the query_posts function you should create a new WP_Query instance.

    $new_query = new WP_Query(
            array(
                'cagtegory_name' => 'seasonal',
                'posts_per_page' => 5
             )
        );
    
    while ( $new_query->have_posts() ) : $new_query->the_post();
    Thread Starter agileArt

    (@pdxdaniela)

    Chris thank you very much.
    I did try get_post (i think) did not get anything at all back.

    will try it (crossing fingers here)& report back.
    D

    Thread Starter agileArt

    (@pdxdaniela)

    nope tried

    $new_query = new WP_Query(
            array(
                'cagtegory_name' => 'seasonal',
                'posts_per_page' => 5
             )
        );
    
    while ( $new_query->have_posts() ) : $new_query->the_post();
        echo '<li>';
        the_title();
        echo '</li>';
    endwhile;

    and also

    <?php
    // The Query
    query_posts( 'cagtegory_name=seasonal&showposts=5' );
    
    // The Loop
    while ( have_posts() ) : the_post();
        echo '<li>';
        the_title();
        echo '</li>';
    endwhile;
    
    // Reset Query
    wp_reset_query();
    ?>

    yes i know. but wanted to see if it worked. it didn’t.

    Thread Starter agileArt

    (@pdxdaniela)

    But this one did work:

    <?php
    $new_query = new WP_Query(
            'category_name=seasonal'
        );
    while ( $new_query->have_posts() ) : $new_query->the_post();
    ?>
    
    <li>
    	<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
    	<?php the_excerpt(); ?>
    	<hr>
    </li>
    <?php
    endwhile;
    ?>

    however there is no limit on posts here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘post filtering/selection.’ is closed to new replies.