You can use the action pre_get_posts. It gets fired after the query object is created but before the query is run.
This is an example from the official documentary for displaying only one category:
In your functions.php add the following:
function my_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '123' );
}
}
add_action( 'pre_get_posts', 'my_home_category' );
Related Posts:
- Is having multiple theme customizers for different pages possible?
- Permanently remove first image from posts
- reason of splitting theme files to multiple files
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- the_post_thumbnail() based on the Post ID
- Design view breaking on Pages
- Use different javascript files for each page on website
- How to remove this function from the homepage?
- How to get custom image size for image uploaded in Customizer
- Want to create Child theme, but already edited Parent theme css files and some php files
- Adding code to child theme functions.php to override parent theme behaviour doesn’t work
- How should I best target dynamically served content?
- How the functions in WP are called in tags
- How to display recent posts on home page with custom HTML
- Add a Second Menu to a theme that only support 1 menu
- Changing the template hierarchy
- How to Insert Shortcodes into Theme?
- Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
- Set WordPress Default Template
- Custom Theme, Custom shortcode not working
- Customizer: Output default value in Customizer CSS
- WordPress does not load page.php, return 404.php
- Displaying the last post on static homepage
- Adding custom directory and PHP files in wordpress
- Show full posts in archive
- WordPress add post format support not working
- Connect WordPress with SharePoint [closed]
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- Move category description below post list in blog
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- Let Users Choose Post Categories
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- 404 error when I acess the second page of post-type
- proper way to add css using functions.php?
- I restricted wordpress by logged users. It’s possible exclude a page?
- What does this mean in wordpress? Easy question
- Showing latest post without 301 redirect
- Translate wordpress date from Italian to English
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Do I have anything to worry about when switching to a default theme to test for plugin conflictions?
- Pagination broken on is_front_page()
- How to integrate noimage picture in this code
- Need oop for wordpress theme? [duplicate]
- How to include custom code on a page that’s set to act as homepage?
- Save Custom CSS file in the upload folder dynamically?
- Warning: printf(): Too few arguments in helpers.php file
- WordPress and PHP Version Upgrade issue [closed]
- home.php show blog posts as grid view
- Override index with a custom PHP page
- Randomize Color Scheme Selection in Theme
- Accidentally deleted php code in WordPress website [closed]
- How can I assign separate stylesheets to different pages?
- Commas in Tag Cloud
- Is there a (offical) way for a theme to deactivate itself and show a message in admin?
- how to get wordpress page url php code [duplicate]
- How to put search bar & logo in the “primary navigation” storefront theme?
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- error_log PHP error log found. This file must not be in the production version of the theme. (wordpress theme check plugin)
- I am having issue in divi woocomerce checkout module. (DIVI theme)
- Styling a category link
- Not able to remove caption shortcode from the content
- File from parent theme imported to child theme doesn’t work – any ideas?
- Commenting requires wordpress login, wordpress discussion and post comments tick boxes are checked
- Display post date also if the date it’s the same for each post
- Conditional Banners
- The style.php file inside theme-engine folder has other content on FTP
- How to override theme’s public static function inside of a trait?
- Menu not updating for logged in users after redirect
- Invalid Argument foreach
- How to Change Site Elements based on referring URL
- how to use 2 index.php file One for mobile and one for desktop
- Having trouble with customizing blog posts on the home page
- loop to return tags in woocommerce in alphabetical order?
- need to edit php file of child theme to remove an element
- Use Custiomizer to setup meta theme color tag
- Insert div after every three posts in home.php [duplicate]
- Rotating Header Images
- Custom Theme, Editor won’t wrap text (i.e. change width)
- Two theme locations for two menus, but only one is showing up
- How to display html code on homepage
- two wordpress sites, two themes, one database, same content
- calling a function from a class in your template
- Showing custom field contents without listing description
- Hide cart when empty [closed]
- WP Knowledge Base Theme bug – Subcategories and Articles, Need to change WP_Query
- Inserting A Feed and Sidebar into an HTML Page
- how to register a second page-template
- Gallery requires a featured image but does not show it in posts/pages
- .htaccess on multisite and roots theme?
- Move wordpress sidebar on homepage up to new position
- Catchable fatal error in appcloud free theme by Tokokoo
- I want Page titles and excerpts to show up on home.php in certain order
- How to create and add js and css file when server is not on my PC?
- Link a lightbox thumbnail to a post instead of opening the lightbox
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- Font Awesome Icons as squares [closed]
- What is considered good practice for registering menu locations?
- WordPress theme requires PHP v >=8.1 – How to a dd different PHP version to docker-composer
- Upgraded php & wordpress but theme broke
- WordPress generating Undefined Variable warning