Im looking to show more data in the search results.
Including; Pages, CPT, ACF etc.
Cheers
Im looking to show more data in the search results.
Including; Pages, CPT, ACF etc.
Cheers
Hi @mike
Welcome to the Frontity community. Good to see that you’re trying out Frontity.
At the moment the wp-source
package only returns search results for posts, as you need to send separate queries for posts, for pages, for each CPT, etc…
However, there is a possible solution. You will need to be using a self-hosted wordpress.org site, rather than a wordpress.com site as your API, as you need to be able to install a plugin.
This plugin will add a multiple-post-type
to the WordPress REST-API that will enable you to search multiple post-types.
You will, however, need to write your own handler to fetch the results and process them. See our docs on the wp-source
package. As part of the params
passed to api.get
you should add a types
array with the posttypes you want to fetch, something like:
types: ['posts', 'pages', 'my-cpt']
Hope this helps.
Hello,
I’m also interested in searching in a CPT, I installed the plugin but I don’t understand on the frontity side how to configure the search.
Do you have an example to propose?
Thanks
Hi @d1cg018, Welcome to the Community!
Here you have additional info on this topic:
In the twentytwenty
theme there’s an implementation of a search feature using WordPress engine (search links as ?s=anyKeyWord
)
Here you have the React components used for that
Taking this into account, if you want to trigger an alternative search when your users go to these search links (?s=anyKeyWord
or any other you may want to use), you can create a custom handler to perform alternative searches
Here you have an example from a member of the community that implemented her own search results link with a custom search
libraries.source.handlers
is a powerful resource in Frontity projects as they allow to define custom links that can be fetched with actions.source.fetch()
Hope this helps
Hi @mburridge, I’m trying to add multiple CPT to the search results but I’m stuck. Where exactly do I have to add this code?
const response = await libraries.source.api.get({
endpoint: "multiple-post-type",
params: { search: params.search, type[] : 'voice'}
});
and why is there : 'voice'
after type[]
?
Could you please give more details? Thanks!