• Resolved kikidok

    (@kikidok)


    Hi,

    I was using the following code: $posts = get_posts('numberposts=8&order=desc&orderby=post_date');
    foreach ($posts as $post) : start_wp();
    to retrieve 8 latest posts orered by posting date in single.php and on my site’s homepage (not blog).

    All was fine till I needed to filter out a certain category, say ’25’. Using if (in_category('25')) continue; wouldn’t work because it would return only 6 entries if there’re 2 category ’25’ posts found as documented in the DOC.

    If I use query_posts("cat=-25") before the start of $post, it will return only 2 posts and not 8.

    Question is, how do I filter out a certain category while listing out 8 latest posts?

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter kikidok

    (@kikidok)

    Never mind, I think I figured it out.

    query_posts("cat=-4&showposts=8");
    if (have_posts()) : while (have_posts()) : the_post();
    seems to work jsut fine for now.

    But if you have more robust suggestion, lemme know 😉

Viewing 1 replies (of 1 total)

The topic ‘Excluding a category when using get_posts’ is closed to new replies.