I have updated, but that doesnât fix the search bug, basically if the home page is another thing than the blog feed, then the search continue showing the home page
this happens with my theme, but also with twentytwenty
the search doesnât show isSearch
Sorry, @alexaspalato, I meant that the bug related to isHome
is fixed.
Regarding the isSearch
issue, the problem is that handlers are the ones responsible for adding that property and return the search result. When a static page is shown as the homepage, the handler being executed for the root link (/
) is postTypeHandler
, which ignores the search query. As the <SearchForm>
component is using /?s=
to build the link with search query, it doesnât work for static homepages.
To fix this you can modify the <SearchForm>
component in /src/components/search/search-form.js
so it uses state.source.postsPage
when building the link with the search query.
// Let's go search for blogs that match the search string
actions.router.set(
`${state.source.postsPage || "/"}?s=${searchString.toLowerCase()}`
);
That way the handler executed is the one for the post archive, which already has the logic for searches.
This is a bug anyway, either in wp-source
handlers or in twentytwenty-theme
.
Iâll open an issue in our repo.
@alexaspalato, I forgot to mention, as handlers are in charge of honor the search query, you would have to add support for that in your featuredCatHandler
as it is the one being executed for the root link (/
).
Juanma already explained how to do so:
@juanma @David Thank you!
I tried to apply these changes in order to make the search work but it gives an internal server error
So for the moment I deactivated the search as itâs not mandatory for the client
and had what I tried to do on this branch
I saw some problems in the code that can be easily fixed:
In this line, you are using parse()
but it should be libraries.source.parse()
:
const { query } = libraries.source.parse(link);
In this one, you donât need to check if endpoint
is "posts"
â there is no endpoint
variable defined in your handler â , you can use state.source.postEndpoint
directly.
const response = await libraries.source.api.get({
endpoint: state.source.postEndpoint,
params: { categories: 1780, per_page: 50, search: query.s },
});
And the last thing is that you forgot to export form
in packages/frontity-starter-theme/src/theme-ui/components/index.js:
export * from "./form";
With those changes, the search bar should work again.
Cheers!
PS: maybe you donât want to restrict searches to post belonging to the category 1780
, right? In that case, you would have to add that parameter when it is not a search.
Thanks, it works!
but effectively I want the search in the whole site, I donât understand how to do that
" In that case, you would have to add that parameter when it is not a search."
You just need to add categories: 1780
if it is not a search. Thatâs what I meant.
Sorry, I still donât understand where and how to add that.
Handlers still quite blurry to meâŚ
Donât worry.
You could write something like this code:
As you only want to restrict the results to a specific category (1780
) when is not a search, you can use query.s
to check which case it is and pass the appropriate params to libraries.source.api.get()
.
const response = await libraries.source.api.get({
endpoint: state.source.postEndpoint,
params: query.s
? { per_page: 50, search: query.s }
: { per_page: 50, categories: 1780 },
});
Thanks, got it, it works