Skip Navigation

[Closed] Relatioship Posts-Products search by title and SKU

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 3 months, 2 weeks ago.

Assisted by: Nigel.

Author
Posts
#2737191
relationship.jpg

Hi, I've Toolset and WooCommerce installed. I've created the many-to-many relatioship Posts-Products.

When I use the Connect Existing Products button to connect Products to the Post, it seems that the searchbox searches in the title and also in the product decription (see image, I look for a word and it displays also results without that word in the title).

Is it possible to limit the search only to the title? Is it also possible to search by SKU?

thanks
Umberto

#2737699

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Umberto

I located the plugin code that handles the requests for these text searches when you are connecting related posts, and I followed through the details.

In the end it uses a standard WP_Query to search for the related posts, using the 's' search parameter.

That searches both the post_title and the post_content, and there isn't a simple way to change that behaviour (nor to add other fields such as the SKU).

There aren't any filters that you can use to intervene in the Toolset code to modify this.

The only option if you need to do this would be to look at the available filters for the WP_Query::get_posts method and modify the generated SQL. The posts_search filter would be your best route in, see https://developer.wordpress.org/reference/hooks/posts_search/

#2739785

Hi Nigel, can you show me an example how to hook the connection query?

I need a condition to hook the search query only when it comes from the connection button.

thanks

#2739983

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If you add a callback to the posts_search filter then you should be able to inspect the $_REQUEST or $_POST globals, the admin-ajax call is submitted with an action "types_related_content_action".

Try dumping $_REQUEST and $_POST to the debug.log in your filter callback and inspect the contents, you should be able to determine whether that action is present or not and how it appears in either global variable to be able to test for it.

The topic ‘[Closed] Relatioship Posts-Products search by title and SKU’ is closed to new replies.