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:
- WordPress Theme variables scope
- esc_attr() right way and use
- why is translation not working on theme?
- Is having multiple theme customizers for different pages possible?
- How to export/import theme customizer settings?
- Check php version before theme activation
- Separate WordPress themes for each category page
- Detection of theme being used
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- How to get the registered sidebar’s name by its id?
- the_post_thumbnail() based on the Post ID
- One button to change all settings in theme customizer?
- Replacing mysql_real_escape_string in WordPress theme
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Activate different theme for temporary preview
- Nice scroll to wordpress
- Twitter feed is showing blank in WP site [closed]
- Can’t Find a Way to Edit the Home Page Content [closed]
- How do I hardcode a WordPress shortcode into my theme?
- Fatal error: Call to undefined function wpsc_cart_item_count()
- How to remove this function from the homepage?
- Widgets not showing in my custom theme
- How the functions in WP are called in tags
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- Add a Second Menu to a theme that only support 1 menu
- Can’t load WP function into external function
- How can I hide Home in my menu in a specific page?
- WordPress: Access a plugin from within a theme
- Getting error when trying to implement site-wide breadcrumbs in Twentytwentyone Theme [closed]
- Reconfiguring WordPress site
- My page.php shows the index.php
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Custom Theme’s “Preview Changes” Doesn’t Work for Previously Published Posts
- two columns of posts on homepage, one of them “favorites”
- How do I link a button I created in theme customizer to a function?
- How to change theme programmatically from a external application?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Does wordpress templates always in files or in database?
- Separation of presentation and code – WordPress
- Why in my theme I can’t see all the statics content under the posts?
- get_template_directory adding FTP root folders in urls
- Design with Elementor and code the rest?
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- blank white page when post/update/change option etc
- How to Update an old theme for the latest wordpress version
- Fatal errors to undefined function in theme 404.php file [closed]
- Problems clearing cache
- show recent posts php code error?
- Implementing custom tag/tax pages
- Change homepage content if user is logged in – BuddyPress
- ‘Bones’ theme: Load stock scripts in footer instead of header?
- Why in this WordPress theme I can’t see the Main Menu?
- Displaying Slider in Front Page (home) using Customizr Theme
- How to make sure relative URL works when site is not on root domain?
- Editing Theme Files on WordPress.com-hosted Site [closed]
- call a string/function from database
- Some problems calling a function into sprintf() inside functions.php template file [closed]
- page 1 is not paged
- Wrap title and excerpt in a div (latest posts block)
- How to set all External Domain Links with nofollow Attribute from Header Footer Content and Excerpt using PHP?
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- How do I use an iFrame for my header in WordPress twenty seventeen?
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- How to use data URL in WordPress?
- wordpress email checker on domain
- Unable to retrieve get_author_posts_url
- Force Sidebar on Full Width page
- Link to index.php from home.php?
- Add the shortcodes from the enfold theme to the other theme
- PHP Error in WordPress Theme
- WordPress child theme, creating a custom php template page
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- Menu to the right of screen on desktop using Bootstrap 4
- style.min.css code issue
- Beginner Developing Theme with Bootstrap – NavMenu question
- How to add Open/Close Toggle button into Twenty Fifteen theme for hiding left sidebar?
- Local WordPress from Git repo, where to set document root?
- Different home page for logged off users
- Editing existing pre-created menus in PHP
- Editted Theme Files Get Updated/Reverted Every So Often
- WordPress pagination broken on blog page, working for search results page
- Shortcode Display From WordPress Dashboard Page Without Using post_id
- Include a php file that is above WP installation hierarchically?
- How to hide something from custom home page with php code?
- Using existing widget code! [closed]
- WordPress Website Featured Image Replacement Issue
- doubled content
- Adding if statement to content for homepage
- Themes with variable width or single columns? I want to display source code
- How can I print out a single stylesheet or javascript link?
- Errors while Loading Most Recent Version of jQuery
- WordPress menu links with images & class selection
- Adding slides to an existing carousel manually
- Predefine Magazine Style Layouts
- Not able to see the error [closed]
- How to remove the intro animation which appears during the load up of some WordPress themes? [closed]
- How to store the_post_thumbnail() value in a variable
- a problem in class in class-wp-hook.php
- Using Featured Image as Hero Background in Word Press
- Font Awesome Icons as squares [closed]