function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-5377' );
$query->set( 'orderby', 'date' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );
Use ASC or DESC for order.
Add code to child themes functions file.
Tested and works.
Related Posts:
- Custom query filter not working on woocommerce category page
- $query->query_var[‘post_type’] not set for pages
- Filter query posts by the count of metas for a meta key
- How to set back query var author_name after unset it?
- Change searched term
- pre_get_posts : ‘post__not_in’ doesn’t work with global variable
- How to change the amount of posts previewed on a page?
- How to reset usual $query on search page to push custom $wpdb query there?
- Merge CPT Taxonomy and Post Taxonomy in $query->set
- custom sorting media with multiple filters – error: not unique table/alias: wp_postmeta
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Limiting a filtered query
- Why the pre_get_posts hook can cause apache stopped working?
- Run search query again without pagination gives no results?
- Set posts per page for parent category and it’s all children
- Filter multiple different main queries on custom pages
- Modify a query using both a text field and a true/false AFC field
- Admin Post List table Query filtering “WHERE” for custom post type
- How to Optimize WP site for millions of posts
- Differences between wpdb->get_results() and wpdb->query()
- Get Terms by IDs with IDs order
- Using WordPress public query variables
- How many WordPress SQL Queries per page?
- pre_get_posts with get_posts
- Slow wp_enqueue_media()
- Advanced Custom Fields – Query Efficiency
- How to display lastest post date in the homepage?
- Can not switch the queried post in pre_get_posts hook
- How to tell if $query_var isset?
- Get IDs of posts currently visible on archive
- Sorting Grids with Essential Grid and Events Manger
- The use of including upgrade.php when building custom queries
- Get the timout value of a saved transient?
- Does meta_query work within get_posts array?
- Slow meta_query with about 4 milion record on wp_postmeta
- How to show more than 5 posts?
- WordPress Find Duplicate Post By Content
- WP Query Sort by meta value (date)
- How to optimize my query filtering out unwanted data?
- mySQL query. ORDER BY meta_key
- Remove posts from query for events whose start date has passed
- how to query multiple categories in wordpress?
- Disable the MySQL query in the main query
- Strange string in console from wpdb query
- Update slug (URL) of pending posts via phpMyAdmin
- How can I get the query that would be run for the archive page?
- Query metas (and not : query posts by metas)
- Select query for a login
- What’s wrong with my $wpdb prepare?
- where should I reset query after using get_results?
- Getting post data from private page
- Exclude featured image and custom field from this get_attachment query
- wpdb print all post meta
- Form and custom query problem
- Export Specific User data without plugin
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Exclude all sticky posts front page twenty twelve
- wpdb COALESCE won’t work
- get csv of users with user_meta
- Custom SQL Query passing array to WHERE p.id
- Query does not return content
- Query posts dynamic date range
- How to read the value of a WordPress $query associative array (hash) key
- Parse query filter in wordpress and relation
- Query posts based on previous query
- get posts by tag to showing in a widget
- Mysql query not working on WordPress 4.2.2
- How do I get all results from my query
- get_post_meta with WP_query
- List WordPress Post and Related Attachments outside of a post page
- How properly create a blog template for wordpress?
- Is there a way to add a link directly into this media query?
- Problem on displaying the results on my query
- Improve performance of slow query
- `offset` WP_Query argument dont work via `pre_get_posts`
- WordPress search in modified post title
- Filter orders by modify date
- How to add url parameter to every search query in SearchWp?
- meta_query not working
- Cannot get sql request from Query object?
- WordPress query: merge meta key (number) values and sort
- Question about of query
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- Modify behaviour of “s” parameter in wp_query
- How to make MySQL search queries with quotes
- Archive query not working correctly
- Custom MySQL Query for Post and Post Meta
- very slow wordpress query with default query
- Multilingual WordPress page – using URL to determine language?
- Custom Query problem access the values
- Exclude sticky posts from query
- If more than 1 image show post link?
- Rewrite Query_Var URL Parameter with Slug
- How to query different categories on index?
- How to specify what kind of is_single post?
- Can’t See Media Queries with Inspect Tool [closed]
- Print data from wordpress sql query
- Can I create my own query in wordpress with traditional methods?
- Query filter on custom post by current author in post widget for elementor query id
- Querying Posts from ACF Repeater Subfield Select Value