Sauter la navigation

[Résolu] Restrict WordPress Archive Text Search to Specific Post Type (with Relevanssi)

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

How to restrict WordPress Archive Text Search results to Specific Post Type?

Solution:

You can edit the WordPress Archive,
in section "Loops Selection", click "Edit" button of option "Home/Blog", enable option "Posts", and save

Relevant Documentation:

This support ticket is created Il y a 2 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Ce sujet contient 10 réponses, a 2 voix.

Dernière mise à jour par zacharyL Il y a 2 années et 10 mois.

Assisté par: Luo Yang.

Auteur
Publications
#2286237

I'm trying to have a contained text search filter for the base Post archives from within a WordPress Archive built within Toolset, however the search results return posts that fulfill the search query that are not just Posts. This is not what I'm looking to have happen in the Blog Post archive.

While this normally isn't a problem in a proper View, as Views inherently filter output based on the post type (or taxonomy) that is configured in the View, since I'm using a WordPress Archive that is associated with a Layout, it doesn't let me restrict the archive view to post type.

#2286531

Hello,

The Toolset Layouts plugin was retired and had been moved to Legacy plugins, it is not recommended to use it in your new project.
We recommend to use the Toolset Blocks plugin to design your website archive page, see our document:
https://toolset.com/course-lesson/creating-a-custom-archive-page/

If you insist on Layouts plugin, you can use WordPress built-in action hook pre_get_posts to setup the post type parameter, see WP document:
https://developer.wordpress.org/reference/hooks/pre_get_posts/

#2286839

I'm not sure how I'd be able to use this action hook for my application. Any help in the integration of pre_get_posts would be greatly appreciated.

Regarding the use of Toolset Layouts, we've been waiting until all the features of Layouts and Views have been incorporated into Blocks. Without the features that we've come to rely on from these two "legacy" plugins, we simply cannot switch to Blocks.

#2286911

I'd also like to point out that Toolset's WordPress Archives are still a feature of Toolset Blocks, and much of that same functionality that is in question is present in Toolset Blocks.

That said, is the issue a matter of association with the WordPress Archive being tied directly to a post type archive Layout (as per the legacy integration)?

#2287297

It needs custom codes, please provide a test site with the same problem, also point out the problem page URLs, I need to test and debug it in a live website, thanks

#2293597

Thanks for the details, I can login into your website, and I assume we are talking about WordPress Archive "Blog Posts Archive":
lien caché

I have tried to display the post type in frontend, with below codes:
Post type: [wpv-post-type]
Where and how can I see the search results "are not just Posts"?
Please provide detail steps to reproduce the same problem, thanks

#2299173
screenshot.jpg

Oh sorry. Yes the general blog post archive, labeled as "News" from the frontend. Here is a link with a search query tied to a URL parameter.

lien caché

I also attached a screenshot to illustrate which post is appearing that shouldn't be. This archive should only output the generic "News/Blog" Posts.

Let me be absolutely clear, we do have a generic search archive, that we use for all post types, so we've left those options open in Relevanssi, otherwise I would have just restricted it that way. I imagine it's the Relevanssi settings that are getting in the way of the proper filtration of this WordPress Archive "view."

#2299545

I have tried these in your website:
1) Edit the WordPress Archive "Blog Posts Archive"
lien caché
in section "Loops Selection", click "Edit" button of option "Home/Blog", enable option "Posts", and save

2) Test the URL you mentioned above:
lien caché
It works fine, I see only posts

Please check if it is fixed, thanks

#2304927

Yeah, I thought that's what I did. I specifically created a brand new WordPress Archive so that I could specifically select the post types and archives in the Loop Selection configuration, but at the time, it didn't appear to make a difference.

Well, now it's clearly working. Thank you for your assistance.

#2305399

I have tried again in your website:
lien caché
It works fine, I see only posts

Is this problem resolved?
If there is new issue in new WordPress Archive, please point out the problem page URLs

#2305887

This is indeed resolved. Thank you.