{"id":3309,"date":"2009-08-10T16:41:14","date_gmt":"2009-08-10T23:41:14","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3309"},"modified":"2021-03-23T08:26:07","modified_gmt":"2021-03-23T15:26:07","slug":"remove-specific-categories-from-the-loop","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/wordpress\/remove-specific-categories-from-the-loop\/","title":{"rendered":"Remove Specific Categories From The Loop"},"content":{"rendered":"\n
<?php query_posts('cat=-3'); ?>\n\n<?php if (have_posts()) : ?>\n<?php while (have_posts()) : the_post(); ?>\n  <h3><\/h3>\t\n  <p><?php the_time('F jS, Y') ?><\/p>\n  <?php the_content(); ?>\n<?php endwhile; ?><\/code><\/pre>\n\n\n\n

The area inside the while<\/tt> loop could be anything, that’s just some example typical inside-loop code. The trick is the first line, and the cat=-3<\/tt> parameter. -3<\/code> in this case is the ID of the category, and you can replace that with any category you wish to remove from the loop. You may use comma separated values here to remove more than one category (e.g. cat=-1,-2<\/code>).<\/p>\n","protected":false},"excerpt":{"rendered":"

The area inside the while loop could be anything, that’s just some example typical inside-loop code. The trick is the first line, and the cat=-3 parameter. -3 in this case is the ID of the category, and you can replace that with any category you wish to remove from the loop. You may use comma […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3229,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":5872,"url":"https:\/\/css-tricks.com\/snippets\/php\/insert-element-every-nth-loop\/","url_meta":{"origin":3309,"position":0},"title":"Insert Element Every nth Loop","date":"March 10, 2010","format":false,"excerpt":"When inside of a loop, you can keep track of the iteration number of the loop (shown below is a simple for loop). Using that iteration number, you can calculate it's modulus of some number (number left over after an even division). If that modulus is zero, you are at\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5805,"url":"https:\/\/css-tricks.com\/snippets\/php\/post-validation-loop\/","url_meta":{"origin":3309,"position":1},"title":"POST Validation Loop","date":"March 2, 2010","format":false,"excerpt":"Assumptions You have an HTML form with a variety of inputs. The action attribute of the form points to a PHP file that contains the code below. Notes about code This code starts by creating an array that holds the name of various inputs being submitted via a POST. getFormData()\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3799,"url":"https:\/\/css-tricks.com\/snippets\/php\/php-zebra-striping-a-table\/","url_meta":{"origin":3309,"position":2},"title":"PHP Zebra Striping a Table","date":"September 4, 2009","format":false,"excerpt":"Table row in a loop:","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":303093,"url":"https:\/\/css-tricks.com\/snippets\/php\/test-if-string-starts-with-certain-characters-in-php\/","url_meta":{"origin":3309,"position":3},"title":"Test if String Starts With Certain Characters in PHP","date":"February 2, 2020","format":false,"excerpt":"We can test if a certain string is the exact start of another string: Testing the position in the string, making sure\u2026","rel":"","context":"With 2 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":20514,"url":"https:\/\/css-tricks.com\/lodge\/artists-website\/028-events-admin-and-ui\/","url_meta":{"origin":3309,"position":4},"title":"#028 – Events, Admin and UI","date":"March 12, 2013","format":false,"excerpt":"We learned how to do a custom loop and output custom data from our custom post types and custom fields in the last video. This time we need to do it again, only for the slightly more complex Events section. We'll need a custom page template just for the events\u2026","rel":"","context":"With 3 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4267,"url":"https:\/\/css-tricks.com\/snippets\/php\/update-values-of-entire-table\/","url_meta":{"origin":3309,"position":5},"title":"Update Values of Entire Table","date":"September 29, 2009","format":false,"excerpt":"This code assumes you are connected to a MySQL database which has a table with Names and Emails. The idea is that it will output a table of every single value from that table, as text inputs. You can then alter the values of these inputs and re-submit, updating all\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3309"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3309"}],"version-history":[{"count":4,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3309\/revisions"}],"predecessor-version":[{"id":336888,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3309\/revisions\/336888"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3229"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3309"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}