PCH: Add category slug support in search#3210
Conversation
📝 WalkthroughWalkthroughThis pull request introduces support for using category slugs in search queries for PCH Related Posts. A new global boolean property is added to the Window interface to control this behavior. The Editor Sidebar’s PHP code now sets this configuration via an inline script, while the TypeScript side updates interfaces and data extraction logic. Specifically, the modification changes the type of sidebar post categories from simple strings to objects containing both a name and a slug, and adjusts component logic to use the flag when determining which value to use in search queries. Changes
Sequence Diagram(s)sequenceDiagram
participant PHP as Editor_Sidebar (PHP)
participant WIN as Global Window
participant TS as RelatedPosts Component (TS)
PHP->>WIN: Inject inline script with wpParselyUseCategorySlugsInSearches flag
WIN-->>TS: Provide configuration via window object
TS->>TS: Check wpParselyUseCategorySlugsInSearches flag
alt Flag is true
TS->>TS: Use category slugs for search filtering
else Flag is false
TS->>TS: Use category names for search filtering
end
Assessment against linked issues
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
This looks good to me! Approved.
Regarding the naming of the filter. wp_parsely_use_section_slugs_in_searches sounds good to me, however conceptually I'm not sure if we should call it use_category_slugs instead, considering that the actual slug comes from the WordPress category, that is matched with the Parse.ly section name. What do you think?
|
Good point, I'll give it a thought. We probably are using WP terminology internally, and in this case it would make sense to go with |
…egory_slugs_in_searches
…-in-pch-search PCH: Add category slug support in search" (831b23b)
Description
With this PR, we're introducing a
wp_parsely_use_category_slugs_in_searchesfilter. Setting it totrue(strict bool, any other value will be considered asfalse) will force PCH's Related Posts search to use the category's slug instead of its name.The filter name is purposefully generic since its use could be expanded to tools outside of PCH Related Posts, for any site setups requiring this configuration.
Edit: Initially, the filter name was
wp_parsely_use_section_slugs_in_searches, but it was renamed towp_parsely_use_category_slugs_in_searchesafter @vaurdan's feedback.Motivation and context
How has this been tested?
wp_parsely_use_category_slugs_in_searchesfilter is set totrueorfalse, as well as invalid values such as strings, numbers,nullandundefined.Summary by CodeRabbit