Skip to content

Custom post types with fullPath parameter fail to match current path due to incorrect singlePrefix handling #922

@lucymtc

Description

@lucymtc

Describe the bug

When using custom post types with the fullPath parameter, HeadstartWP fails to correctly match posts to the current URL path. This occurs because the core SinglePostFetchStrategy always adds the singlePrefix (custom post type slug) without considering whether a fullPath parameter is provided.
https://github.com/10up/headstartwp/blob/develop/packages/core/src/data/strategies/SinglePostFetchStrategy.ts#L185

This causes path matching to fail when fullPath is provided because:

  • The fullPath parameter already contains the complete path including the post type slug.
  • Adding the singlePrefix creates an incorrect path comparison.
  • Posts never match their actual URLs when fullPath is used.

When params.fullPath is provided, the singlePrefix should be omitted since the full path already contains the correct post type slug.

Example Scenario: Translated Slugs
In a multilingual site, a custom post type "webinars" might have:

  • Default language post type slug: /webinars/my-webinar/
  • Translated post type slug: /webinare/mein-webinare/ (DE)
    When using fullPath with the translated URL, the current logic incorrectly adds /articles/ prefix, making it impossible to match /webinare/mein-webinare/

Setting matchCurrentPath to false is a workaround but still an issue if 2 posts have the same slug for EN and DE
/webinars/my-webinar/
/webinare/my-webinar/
It will always render the content of the first post in the response.

Steps to Reproduce

Set up a multilingual WordPress site with custom post type.
Create a custom post type with translated slugs wit Polylang settings
Add fullPath to the request of a single post for the translated post version
Navigate to a translated custom post type URL
Observe that the post is not found, returns 404
Set matchCurrentPath to false and observe the post is found.

Screenshots, screen recording, code snippet

No response

Environment information

WP 6.8.2
Polylang Pro 3.6.7
@headstartwp/core 1.5.0-next.8
@headstartwp/next 1.5.0-next.9

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions