I hope you are well today and thank you for your question.
You can configure the search form and decide which custom fields to search as shown in this screenshot https://imgur.com/a/lOcjJrM
Could you please share the screenshots of the screen where you have created and configured the custom fields and also share your website URL so that I can troubleshoot it?
Best regards,
You can see the site at https://vossity.com
The custom field is selected properly. It works to search the custom field, it just doesn’t search through the post object meta data properly.
For example, do a search for ” evolvh ”
You will see the brand come up, which is a Custom Post Type and it is searching by the post name, and then you see ONE product show up that has the brand in it’s text and none of the other products show up.
Now, do a search for ” 5524 ” which is the ID of the brand (custom post type) named “evolvh”
You will see that now ALL of the other products show up because it is searching that custom field [brand] which is applied to WooCommerce products, but it is ONLY searching by the ID, and not any other meta data such as [name].
I know it is using the custom field, because when I remove the custom field from the search in your menu (same menu as your screenshot above), I can’t find these products by searching “5524” anymore. So that means that when doing the search for the custom post type it is matching on the ID but it is not matching on the NAME or SLUG.
The custom field on the Woocommerce Products is an Advanced Custom Fields, field called “Relationship” which ties to the post object for the custom post type of “Brand”.
https://www.advancedcustomfields.com/resources/relationship/
There are two ways to control the output of the custom field data through ACF. One is to grab the WordPress post object, and the other is to grab just the ID. I am grabbing the whole post object so that we can get the slug or name, etc.
-
This reply was modified 3 years, 8 months ago by badjesus.
-
This reply was modified 3 years, 8 months ago by badjesus.
Thank you for your detailed reply.
I understood it.
So that means that when doing the search for the custom post type it is matching on the ID but it is not matching on the NAME or SLUG.
Could you please tell me what you are referring to here as NAME and SLUG and share the screenshot of it?
For screenshots, you can simply provide a link to an image through Google Drive, Dropbox, screencast.com, http://imgur.com/ or other image service. 🙂
I am not sure what you are asking.
If you are asking if I am doing something custom, I am not.
I am talking about the standard WordPress SLUG and NAME that is in the post object data.
Every post in WordPress has a SLUG (the end URL that is used)
Every post has a NAME (the title of the post).
When you grab a post object, there are many meta data fields.
The search is ONLY showing results when we enter the search string as the ID.
But no users on the planet is going to search for an ID. They are going to search to try and match the POST NAME.
I am not sure what you want a screenshot of.
For now, to get around this, I just created a new custom field, and I am dynamically populating this with just the post_object custom fields post_title
So when a post is saved, if it is a product, and if we have the custom field “brand” populated, then we grab the $post->post_title and we use that to populate a new field called “brand_name” and now my search settings in your plugin is also set to search this new custom field (“brand_name”). Now it is working to search the brand but I have to update every product to save this field.
First of all, I want to make it clear that I know what is post slug and name.
It seems some misunderstanding between us here, therefore, I want to get some screenshots from you so that we will be on right track.
You didn’t share the screenshots but this not an issue as I will try my best to make it clear by sharing the screenshots.
Please note the plugin searches posts and products by its title, content, excerpt, custom fields and categories but not by its ID or slug.
The plugin searches whatever you add in the custom fields whether it is ID or anything else.
To search product title or name, please make sure that you have configured the search form setting as displayed in this screenshot https://imgur.com/a/4B1YvKb
Please advise if you have more questions.