• Hi there,
    I am trying to use the category_name parameter to exclude certain posts from showing in the WordPress loop. I can get the desired effect to work using straight up “cat=-4” and targeting the post ID, but I am having trouble getting it to work using the category name.

    The code also only shows the latest post.

    My working code is this:
    <?php query_posts("showposts=1" . "&cat=-4"); // show one latest post only ?>

    My desired code would be
    <?php query_posts("showposts=1" . "&category_name=-All Work"); // show one latest post only ?>

    I would even be happy using the category slug, but I can’t figure that out either. Has anyone encountered this before and could point me in the right direction?

    Much appreciated.

    Ryan

Viewing 1 replies (of 1 total)
  • I don’t think you can exclude by category name, but you can always get the id using the name, and then exclude the id. I think this will work:

    <?php $id = get_cat_ID('All Work');
    query_posts("showposts=1&cat=-$id"); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘category_name to exclude posts’ is closed to new replies.