To exclude posts from a WordPress page, change the query that supplies those posts—do not hide them with CSS. For an existing blog, homepage, archive, or feed loop, use the pre_get_posts hook and set category__not_in to an array of numeric category IDs. For a template that creates its own loop, use a separate WP_Query with the same argument.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
The important details are choosing the correct query, using category IDs rather than slugs, and limiting any hook callback to the intended front-end main query. The examples below show how to exclude one or several categories without breaking unrelated loops or pagination.
As an Amazon Associate I earn from qualifying purchases.
Recommended Free Tools
What category exclusion actually changes
WordPress builds a query before it retrieves posts for a blog index, static page, archive, search result, or feed. Category exclusion changes that query so matching posts are not returned in the first place. The posts remain published and accessible through any other query that includes them; they simply do not appear in the particular list you changed.
This is different from a CSS solution. CSS can hide a card after WordPress has already queried and rendered it, but it does not remove the post from the HTML, pagination calculations, feeds, or other consumers of the query. Query-level exclusion is the appropriate solution when the requirement is “do not include posts in this list.”
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
Identify the page and the category ID first
Determine which request you want to change
“WordPress page” can mean several different requests:
- Blog index: the page WordPress treats as the posts page. In a normal blog setup, the main query reports this with
$query->is_home(). - Static front page: a page assigned as the site front page. Its main query is not automatically the same as the posts-page query.
- Category or other archive: a taxonomy or date archive with its own main query.
- Feed: an RSS or other feed request, which may need an explicit feed condition.
- Custom page template: a template that runs a second, custom loop rather than relying on the page’s main query.
Write down the exact request before editing PHP. A condition that works for the blog index may do nothing on a static front page or may affect the wrong archive.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteFind the numeric category ID
The category__not_in parameter expects category IDs, not category names or slugs. In the dashboard, open Posts > Categories and edit the category. The category’s edit URL or term information exposes its numeric ID. If you are working in code, WordPress term APIs can also retrieve the term object and its term_id.
For example, if the category ID is 12, use array( 12 ). Do not pass 'news', 'News', or a URL slug to category__not_in.
Choose the right implementation
| Situation | Recommended approach | What you must control |
|---|---|---|
| The site’s existing blog, homepage, archive, or feed loop must change | pre_get_posts |
Check that the request is front-end, is the main query, and is the exact page or request type you intend to alter. |
| A template owns a separate list of posts | A dedicated WP_Query with category__not_in |
Set post type, pagination, and loop output inside that custom query. |
You are considering replacing the main loop with query_posts() |
Do not use it for this job | Use pre_get_posts to modify the existing main query, or create a separate WP_Query. |
The distinction matters because pre_get_posts receives the query object before it runs, while a custom WP_Query creates an additional query under your control.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Exclude a category from the existing blog or home query
For the normal posts index, add a callback to pre_get_posts. This example excludes category ID 12 only from the front-end blog query:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →<?php
add_action( 'pre_get_posts', 'exclude_category_from_page' );
function exclude_category_from_page( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
// Exclude category ID 12 from the blog/home query.
if ( $query->is_home() ) {
$query->set( 'category__not_in', array( 12 ) );
}
}
Replace 12 with the category’s real numeric ID. The early return prevents dashboard queries from being altered. The is_main_query() check prevents the callback from changing secondary loops such as a sidebar widget, a related-posts block, or another component that happens to run during the same request.
Exclude several categories
Pass every category ID in the array:
<?php
$query->set( 'category__not_in', array( 12, 18, 25 ) );
Posts matching any of the listed category IDs are excluded from that query. Keep the array numeric and comma-separated.
Use the correct condition for your front page setup
is_home() identifies the posts index, not every page that visually looks like a homepage. If the site uses a static front page, first decide whether you want to change the posts page, the static front-page query, or a custom post list embedded in the page. Then use a condition that matches that request on the passed $query object.
For an archive or feed, combine the same exclusion with the relevant query condition. The principle is unchanged: check the request type, confirm it is the main query, and set the exclusion only there. Avoid broad callbacks that set category__not_in for every front-end request unless that site-wide behavior is intentional.
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Exclude a category from a custom page loop
Use a separate WP_Query when the template is responsible for fetching and displaying its own posts. Include pagination arguments in that query so navigation reflects the filtered result set:
<?php
$posts = new WP_Query(
array(
'post_type' => 'post',
'category__not_in' => array( 12 ),
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
)
);
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
// Output the title, excerpt, date, and other fields here.
}
// Output pagination for this custom query here.
}
wp_reset_postdata();
The post_type argument keeps this example focused on standard posts. The paged value carries the current page number into the custom query; without it, a page-two request can show page-one results again. After the loop, wp_reset_postdata() restores the global post data for the rest of the template.
A custom query is usually the cleanest choice when a page contains a hand-built post grid and the site’s primary query should remain unchanged. It also lets different components on the same page use different category rules.
Alternative syntax with a negative category ID
WordPress also documents category exclusion through the cat argument. Prefix each category ID with a minus sign:
<?php
$args = array(
'cat' => '-12,-18',
);
$posts = new WP_Query( $args );
This excludes categories 12 and 18. The syntax is useful when the rest of a query already uses cat, but category__not_in is generally clearer when the code’s purpose is specifically to express exclusions. Do not combine a category slug with the negative syntax; the values are numeric IDs.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Where to put the code safely
Site plugin
A small site-specific plugin is a durable location for query behavior because it is independent of the visual theme. Create a plugin file with a valid plugin header, place the hook and callback in it, and activate it from Plugins. This keeps the exclusion when the theme changes.
Active or child theme
You can place the callback in the active theme’s PHP code or, preferably, a child theme if the site’s design is inherited from a parent theme. A parent-theme update can overwrite direct edits, so keep a copy of the change and use version control or another backup process.
Deployment precautions
- Back up the site and database before editing PHP.
- Check the category ID on the same site where the code will run; IDs can differ between installations.
- Make sure the file containing the callback loads before the request’s main query is executed.
- Use the site’s PHP coding standards and syntax supported by its WordPress and PHP versions.
- Test while logged out or in a private browser window so cached admin views do not mislead you.
Common mistakes and precise fixes
The category still appears
- Wrong value type: replace a slug or name with the numeric
term_id. - Wrong request condition: verify whether the page is the posts index, a static front page, an archive, or a custom loop.
is_home()will not identify every page labeled “Home.” - Cached output: purge page, object, or reverse-proxy caches after changing the query, then retest.
- Another loop is rendering the post: the main query may be filtered while a widget or custom block runs its own unfiltered
WP_Query. Add the exclusion to that separate query as well if it should also be filtered. - The callback never loads: check that the plugin is active or that the edited theme/child-theme file is the one the site actually uses.
Unrelated lists lose posts
This usually means the callback changes every query. Keep both safeguards:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →<?php
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
Then place the $query->set() call inside a narrow condition for the intended page or request. If you intentionally need a site-wide exclusion, document that decision and test search, archives, feeds, widgets, and any custom loops separately.
The dashboard or an editor preview behaves strangely
An unguarded pre_get_posts callback can affect administrative queries. The is_admin() early return prevents that in ordinary requests. Preview and editor screens can involve additional requests, so inspect each request type rather than assuming the front-end condition covers them.
Best Value
Pagination is wrong in a custom loop
For a custom WP_Query, pass the current paged value and generate pagination from that query’s totals. Do not rely on the global main query’s pagination when the displayed list comes from a different query.
Using query_posts() caused side effects
query_posts() replaces the main query and can interfere with pagination, globals, and other template behavior. For an existing main loop, adjust the original query with pre_get_posts. For an additional list, instantiate WP_Query and reset post data after the loop.
Apply exclusions to archives and feeds deliberately
Excluding a category from the blog index does not automatically establish the same rule for every other request. Decide whether the category should be absent from:
- the posts page only;
- the static front page;
- category, date, author, or other archives;
- RSS or other feeds; or
- all of the above.
Then add separate, readable conditions for those request types. A feed may be consumed outside the website, so test it directly after changing its query. An archive condition should be specific enough that you do not unintentionally remove posts from unrelated archive pages.
A practical testing checklist
- Record the category ID and confirm that at least one known post belongs to it.
- Open the target page in a logged-out browser and verify that the known post is absent.
- Confirm that a post from an allowed category still appears.
- Check page two of the listing, if pagination exists.
- Open a sidebar, related-posts area, or other secondary list and confirm it changed only if you intended it to.
- Test the site’s relevant archive and feed URLs if those requests should share the exclusion.
- Open the dashboard and edit a post to ensure administrative screens still show normal category data.
- Purge relevant caches and repeat the front-end checks.
Which method should you use?
Use pre_get_posts when you need to alter the query WordPress already created for the blog index, an archive, or another main request. Its strength is that it preserves the normal loop and pagination while giving you a precise point to add the exclusion.
Use a dedicated WP_Query when a template or component owns a separate post list. You can then give that list its own categories, post type, ordering, and pagination without changing the rest of the page.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use the negative cat form only when it makes an existing argument set easier to understand. Otherwise, category__not_in states the intent more directly.
Quick Recap
Key points to remember
- Category exclusion belongs in the query, not in presentation-layer CSS.
category__not_inaccepts an array of numeric category IDs.pre_get_postsis the normal way to adjust an existing main query.- Guard callbacks with an administrative check and
$query->is_main_query(). - Match the conditional—such as
is_home()—to the exact request you want to change. - Preserve the
pagedargument and reset post data in custom loops. - Avoid
query_posts()for category exclusion.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

