What is the ACF add-on
The ACF add-on is an extension that makes it possible for the ACF plugin and WPSOLR to work in tandem. You can now use ACF fields with WPSOLR. This will allow you to create custom facets.
Install the ACF plugin
Install the Advanced Custom Fields plugin and activate it.
Create an ACF facet for WPSOLR
Click on “Custom Fields”, then on “Add new”
Choose a title for the new field group.
Add a new field. Choose a label and a name then choose the field type. Save when you’re done.
Then scroll down and choose where the field group will be applied. I chose to use it on WooCommerce Products. You can choose to use many other field types as well. Here i am going to choose the “Select” field.
Then modify the products.
Then head over to the WPSOLR plugin and make the necessary changes. Scroll down and read the rest of this guide to get a better understanding of the WPSOLR configuration that you need to do.
We can see there is exactly the number of products assigned in each choice and the products are displayed correctly when clicking on the “tshirt” checkbox.
Create additional ACF facets
We can create a lot more ACF facets that can fit your individual needs.
Add a repeater with two text fields
Add a new ACF field then choose a name. Then choose the field type, in this case i’m choosing the “Repeater” field type.
Add a repeater field. This will be a text field for the product type.
Then add another field for the product color. When you’re done save, then edit a product.
You should see something like this. Fill in the information then save. Then head for the WPSOLR admin.
Click on the “Data” section you will see later in this article.
Then select our new fields.
And select the new fields to use as filters.
Choose a label for the product color and a layout.
Then choose a label for the product type and a layout. Then test your website search.
As you can see we now have a new filter that can sort products by color and product type.
Add a repeater with fields for uploading files.
Create a field for the product manufacturer and select the repeater field type.
Then create two repeater field, one for the manufacturer history, the other one for the list of the total number of manufacturer products, then save.
Edit a product then upload the two files. Since we are dealing with files, we will not be able to generate a facet but if you search for a word that is contained in one of the files, you should find the right product.
As you can see, We ended up on the right product.
Add a repeater that contains another repeater and fields for uploading files .
Create a new field and choose the “Repeater” field type.
Create a sub repeater field and choose the “Repeater” field type again.
Add another sub field and choose the text field type.
Here I chose to add another text field.
Then add two other fields.
The two fields will both have the “File” field type. Save and edit a product.
Add the product title, the category and the two wikipedia files. Save and configure WPSOLR. Then test your website search.
The WPSOLR facets work correctly.
And website search works as well. Fabric was a word used in the Tshirt wikipedia page. We can see that WPSOLR returned the correct result.
Add a file field type
Add a new field. Choose a label and select the “File” field type. You can also choose the return value. You can return it as an array which return the data as an array, as a file url which returns the data as a string and as a file id which returns the data as an integer. This is useful if you want to use this field in your PHP code.
Edit a product and upload a file in the new field.
Now when you search for words used in the file, in my case “march 20”, WPSOLR should return the products that we uploaded the file too.
We can see that WPSOLR search is working well.
Add a clone field
Create a new field. Choose a label and pick the “Clone” field type. Then pick the field that you are going to clone. Choose the way you want to display the new field. When you’re done save and edit a product.
As you can see we have successfully cloned the email field. Configure WPSOLR then test your website search
We have successfully cloned the email field.
Add a flexible content field
Add a new field then choose a label and select the “Flexible Content” field type.
Then choose a label for the new flexible content layout and select a layout. Then add a subfield. In my case it is a repeater.
Add a field inside the new repeater. Here I chose a text field.
And add a second field.
Add a second field in the flexible content layout.
Here i added a text field. Then i am going to add two new fields for the layout.
Next I am going to create a second flexible content layout.
Here I created a second layout with a new file field by clicking the “Add New” button.
Then i’m going to add two new fields.
I chose to use the file field type both times.
I added a new layout with a text field.
Then I added two other text fields. When you’re done save and edit a product.
Here I added four reviews of our first client.
Here I added the three review of our second client in the file format.
Finally I added the three reviews of the third client. When you’re done save and configure WPSOLR. Then test website search.
Add an email field
Create a new field then choose a label and a field type. Save then edit a product.
Enter the email in the newly created field. Then add the filter in WPSOLR. The process is similar to the one in the “Add a repeater with two text fields” section.
The new filter is added when we search on the frontend.
Add a URL field
Add a field and choose a label and a field type. I chose the “Url” field type.
Then edit a product and enter a url. Configure WPSOLR then do a website search.
Add a password field
Add a new field a choose the field type password, then edit a product.
Then type in the password you want in the product. Configure WPSOLR then search your website.
We can see the new filter which has been added.
Add a textarea field
Add a field that will be used to add additional information about a product. Select the Text Area field type if you want to be able to write on multiple lines.
Edit a product and enter the text you want your users to be able to filter. Configure WPSOLR then test the website search
Add a text field
In the previous section we added a textarea. Here we will add a text field.
Edit a product and enter the seller name. Then configure WPSOLR and test your website search.
Add a number field
Here we are going to use a number field.
Edit a product and enter a zip code.
Then test your website search.
Add a radio field
Here I added a custom field for the product rating. I gave the field a label and chose “Radio Button as a field type”. Then i entered three choices so we can choose the rating. Then i saved.
Then edit a product and choose a rating. Save then configure WPSOLR like I did before.
Then test your website search. As you can see we have one product that has the “Good” rating.
Add the checkbox field
Create a new field. Add a label and choose the checkbox field type. Then type in the different choices. I used the label: value format in this example. Save and edit a product.
Click on the checkboxes. Save and configure WPSOLR. Then test website search.
As we can see the new filter is working correctly.
Add a Select field
Create a new field. Choose a label and select the “Select” field type. Then enter your choices in the same format we did in the previous section. Then save and edit a product.
Choose an option in the Select field then save. Configure WPSOLR and test website search.
We can see the filter is being displayed correctly.
Add a True/False field
Add a new field for the True/False field type. I used the label 2 day shipping so i could select if it was available for each product. Add a message to display next to the checkbox.
Edit a product and check our new field. Save then configure WPSOLR.
Click on “Data” in WPSOLR.
Then select our newly created field.
Click on “Filter” in the sidebar.
Then select our new field. Add a label and a layout.
If you don’t want your item label to be a number, Click on “Override each item label”.
Then type in the facet value. when you’re done save.
Test your website search.
Add the “What you see is what you get editor”
Add a new field and choose “Wysiwyg Editor” field type.
Edit a product then scroll down to the new field. You can enter text or insert an image. Configure WPSOLR when you’re done.
Add a message field
Add a new field and choose the message field type. type in a message.
Edit a product then test website search.
We find the correct product by typing the message in the search field.
Add a tab field
Create a new field. Enter a label and choose the “Tab” field type. You can then choose the placement of the tab. Then save.
Create a new field. Enter a label and choose a field type. This will be a new tab for the previous field.
Add two new fields. One will have the “Tab” field type, the other will have another field type. These two fields will be our second tab.
Do the same thing again so we can have a third tab. Save and edit a product.
Fill in the fields, then save and configure WPSOLR. When you’re done test website search.
The filters are displayed correctly.
Add the ACF facet to the content
Click on Products in the WordPress admin sidebar.
Then edit a product.
Scroll down until you find the field you created in the previous step. If the product is a tshirt, click on the checkbox. When you’re done save.
Create a WPSOLR index
Click on the WPSOLR plugin then click on the “Connect to your search server or search service” button.
Fill in the fields presented to you. Choose the earch engine, in my case it is Elasticsearch. Then choose the hosting service. Pick a name and fill in the endpoint url you got from the search engine service. Then fill in the user and the password you got from the search engine service.
Activate the WPSOLR extensions
Go to “Activate extensions”
Then click on “ACF” in the sidebar.
Then click on the first checkbox to activate the extension. If you click on the second checkbox it will use the ACF field label instead of the field name.
This what you will see on the frontend part of the website before the second checkbox has been checked.
This is after. The third checkbox will index ACF file fields. ACF file fields are fields where you can upload files like pdf files or text files. When you’re done save.
Click on “Theme” in the sidebar.
And click on “Use this extension”.
Configure your WPSOLR facets
Click on “Define your search with ‘No index selected'”
Click on “Search” in the “Replace front-end archives” section and choose a search engine index. In my case it was elasticwpsolr.
Click on “Data” in the sidebar.
Select the data you would like to search in.
Choose the taxonomies you would like to use.
And then select the fields you would like to use. Don’t forget to choose the ACF field you created earlier.
Click on “Filter” in the sidebar.
Click on the filters you would like to use. Add the ACF field.
Then edit them. Here I chose to modify the layout. I decided to use the “Select box” layout. You can change other things about the filters like the label. On the ACF field, click on “Override each item label” then enter a facet value. I chose to enter “True”. When you’re done save your changes.
Index the content
Click on “Send your data”.
Click on “Index selected post types in index ‘elasticwpsolr'”. Your data should start indexing.
Add the WPSOLR facet widget
Click on the “Customize” button on the front part of the website then click on “Widgets” and on “Sidebar”.
Then add the WPSOLR Facets.
Test website search
Go to the front part of your website.
The filter we just created works very well. If you want a more detailed explanation, you can watch this video: