Skip to content

Posts, Post Types: Allow a custom post type's latest posts on the home page - #16155

Open
faisalahammad wants to merge 18 commits into
WordPress:trunkfrom
faisalahammad:ticket/19958-unit-tests
Open

faisalahammad wants to merge 18 commits into
WordPress:trunkfrom
faisalahammad:ticket/19958-unit-tests

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Nov 22, 2026 •

Copy link
Copy Markdown

Lets a site show the latest posts of a custom post type on the home page. A post type opts in with show_in_home_page_list, and the new post_types_allowed_on_home_page filter can change the list.

This builds on #10798 by @pbearne, merged with trunk, and fixes the problems found by the tests and in review.

Changes

1. The post type is stored in its own option. Core and bundled themes expect show_on_front to be posts or page. Saving a post type name there meant the setting could not be saved, is_front_page() returned false on a default site, and trashing the front page no longer reset the settings.

// Before
update_option( 'show_on_front', 'book' );

// After
update_option( 'show_on_front', 'posts' );
update_option( 'show_archive_on_front', 'book' );

2. Only the main home query is changed. Widgets and other secondary queries still return posts.

// Before
if ( $this->is_home && 'page' !== get_option( 'show_on_front' ) && empty( $query_vars['post_type'] ) ) {

// After
if ( $this->is_home && $this->is_main_query() && empty( $query_vars['post_type'] ) && 'posts' === get_option( 'show_on_front' ) ) {

3. The Reading screen keeps the trunk radio buttons and page dropdowns. A separate "Homepage post type" row with its own label is shown when a post type other than post is available. Custom post type entries are no longer listed in the static "Homepage" dropdown, because choosing one redirected to its permalink.

4. New get_home_page_post_types() applies the filter in one place. It skips pages and post types that are not registered.

Screenshots

Settings > Reading with a book post type that opts in.

Before (trunk) After
Reading settings before Reading settings after, with the Homepage post type setting

Testing instructions

  1. Register a public post type with 'show_in_home_page_list' => true and publish a few entries.
  2. Go to Settings > Reading, keep "Your latest posts", pick the post type under "Homepage post type" and save.
  3. Visit the home page and page 2.
  4. Switch to a static page, save, and visit the home page.

Expected: steps 2 and 3 list only the chosen post type, with no redirect. Step 4 shows the static page as before.

Testing done

  • Full single site PHPUnit suite passes (32183 tests). The multisite query, option and post groups pass.
  • PHPCS reports no errors on the changed files, and PHPStan reports no errors on the changed source files.
  • Manual check on a local trunk install: saving the setting, the home page and page 2.

Open points

  • When another post type is on the home page, regular posts have no listing page of their own, and the post archive link still points to the home page.
  • The Customizer and REST settings do not expose the new option yet.
  • Existing sites fall back to post by default. No database version bump is included.

Trac ticket: https://core.trac.wordpress.org/ticket/19958

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5, Claude Sonnet 5.5
Used for: Bug analysis, unit tests, code changes, screenshots and this description. I chose the approach and take responsibility for the result.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

adamsilverstein and others added 16 commits September 9, 2020 14:49
# Conflicts:
#	src/wp-admin/options-reading.php
Co-authored-by: Adam Silverstein <adam@earthbound.com>
Co-authored-by: Adam Silverstein <adam@earthbound.com>
Co-authored-by: Adam Silverstein <adam@earthbound.com>
…tests

# Conflicts:
#	src/wp-admin/options-reading.php
#	src/wp-includes/post.php
Rewrites the home page query tests to follow core conventions and
covers the `post_types_allowed_on_home_page` filter, `is_front_page()`,
saving the `show_on_front` option, explicit and secondary queries,
and the static front page path.

Adds tests for `_reset_front_page_settings_for_post()` so trashing or
deleting the front page or posts page keeps resetting those options.

See #19958.
@github-actions

This comment has been minimized.

Removes the demo code added to the Twenty Twenty and Twenty Twenty-Five
theme `functions.php` files.

Documents the `show_in_home_page_list` argument in `register_post_type()`
and adds it as a property of `WP_Post_Type` with a default of false.

Points the `post_types_allowed_on_home_page` filter references at the
file without a line number, and cleans up the filter docblock.

See #19958.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Keeps `show_on_front` limited to `posts` and `page`, and saves the chosen
post type in the `show_archive_on_front` option. Core and themes that read
`show_on_front` keep working, which fixes saving the setting,
`is_front_page()` on a default site, and resetting the front page and posts
page when they are trashed or deleted.

Only the main query on the home page is changed, so secondary queries still
return posts.

Restores the static page radio buttons and page dropdowns, and adds a
separately labelled "Homepage post type" setting.

Adds `get_home_page_post_types()` so the
`post_types_allowed_on_home_page` filter is applied in one place.

See #19958.
@faisalahammad faisalahammad changed the title Tests: Add unit tests for custom post types on the home page Posts, Post Types: Allow a custom post type's latest posts on the home page Nov 26, 2026
@faisalahammad
faisalahammad marked this pull request as ready for review November 26, 2026 20:50
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein, pbearne, faisalahammad.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants