GET FREE VERSION GET THE PRO VERSION

Advanced Custom Fields ( ACF )

Searching for fields created with Advanced Custom Fields ( ACF ) plugin.

In this article

Overview

Key features of integration:
  • Search via ACF fields. Search for products by their ACF fields values.
  • Display ACF fields values. Display value of any ACF field inside products search results list.
  • Search results filters. Create search results filters based on ACF fields values.

Advanced Woo Search PRO plugin version comes with full support for Advanced Custom Fields ( ACF ) fields.

All ACF plugin fields content can be available for search and will display products related to these fields.

Also you can display any of the custom fields right inside the search results box and create search results filters based on any ACF field.

Enable the search for any products custom fields created via ACF plugin.

Plugin supports all fields types of ACF plugin: Text, Text Area, Number, Email, URL, Wysiwyg Editor, Link, Post Object, Page Link, Relationship, Taxonomy, User.

If any of these fields insert inside layout fields like Group, Repeater or Flexible Content AWS plugin will also find them.

Custom fields search enable

Custom fields search enable

To enable support for ACF fields search first of all it is needed to activate Custom fields search source from the plugin search page.

Then click on the gear icon near it. You will see the list of all available custom fields of your site. All of them are disabled for search by default. You need to find here ACF fields then must be searchable and activate them.

Enable ACF custom field

Enable ACF custom field

After you do this all content that was generated via enabled ACF fields will be available for search.

Display Custom Fields

It is possible to display any ACF custom fields right inside products' AJAX search results. You can display any type of custom field that the ACF plugin provides.

To display such fields you need to use some custom code snippets. These snippets need to be placed somewhere outside the plugins folder. The best way is to use some plugin for adding code snippets ( for example, this one ). Or just place the code inside your theme functions.php file.

Example: with the ACF plugin we created a new custom field Product Num of type Text.

ACF custom field

ACF custom field

So to display this custom field for any product inside search results that has not empty value for it just use the following code snippet:

add_filter( 'aws_excerpt_search_result', 'my_aws_excerpt_search_result', 10, 2 );
function my_aws_excerpt_search_result( $excerpt, $post_id ) {
    $field_name = 'product_num';
    if ( function_exists( 'get_field' ) ) {
        $field = get_field( $field_name, $post_id );
        if ( $field ) {
            $excerpt = $excerpt . '<br>' . '<span style="margin-top:3px;display:block;color:#000;font-size:11px;font-weight:bold;">Product Num : ' . $field . '</span>';
        }
    }
    return $excerpt;
}

So after adding this code product search results with field product_num will display it inside AJAX results.

ACF field inside search results

ACF field inside search results

Filter Search Results by ACF Fields

Create products search results filter based on any available ACF field. With such filters you can show/hide products based on custom fields values.

Steps to create a filter:

1. Open the plugin settings page -> Search Results tab and scroll down to Filter Results section.

2. Click on Filter products search results button to create a new filter rule.

Filters for products search results

Filters for products search results

3. Set following filter rule:

ACF: Fields -> {Field_NAME} -> equal to -> {Field_Value}

So you need to choose a custom field name and field value for the filter rule. Also choose from equal to and not equal to operators.

Filter based on ACF field

Filter based on ACF field

4. Just click on Save Changes button and your newly created filters are ready. Just check the plugin search form to make sure that all is working as should.

Fields types

Below we will cover different types of ACF fields and how to use them relative to the Advanced Woo Search plugin.

Text Field

For example, you created text field type.

Text field type

Text field type

And you have a product called T-Shirt with Logo. So for this product you set ACF text field value to, for example, some custom text.

Text field inside product

Text field inside product

Right after you save this product with this custom field content it will be available for search ( of course if you enable this field from the plugin settings page ).

Search for content inside product custom field

Search for content inside the product custom field

 

Another example - with link relational field. This field type gives the option to create link relations with any other page or post type.

Link field type

Link field type

We will edit this field for T-Shirt with Logo product. For example, let's create a link to another product that is called Hoodie with Zipper.

Link relational field inside product

Link relational field inside product

So now when searching for Hoodie with Zipper search results will show not only this product itself but and T-Shirt with Logo.

Search for content inside product link field

Search for content inside the product link field

 

Post Object Field

Post object field gives the option to attach any custom post type to any other one.

Post object field type

Post object field type

In our example we will attach to T-Shirt with Logo product a V-Neck T-Shirt product.

Post object field inside product

Post object field inside product

Now when searching for V-Neck T-Shirt search results will show not only this product itself but and T-Shirt with Logo.

Search for content inside product post object field

Search for content inside the product post object field

 

This field type gives the option to attach a link to any page or post type.

Page link field type

Page link field type

Lets attached to T-Shirt with Logo product Hoodie with Pocket product.

Page link field inside product

Page link field inside product

Now when searching for Hoodie with Pocket search results will show not only this product itself but and T-Shirt with Logo.

Search for content inside product page link field

Search for content inside the product page link field

 

Relationship Field

Relationship field gives the option to create a relationship between two posts.

Relationship field type

Relationship field type

Lets create a relation between T-Shirt with Logo product and Checkout page.

Relationship field inside product

Relationship field inside product

Now when searching for Checkout page search results will show T-Shirt with Logo product.

Search for content inside product relationship field

Search for content inside the product relationship field

 

Taxonomy Field

With taxonomy field it is possible to attach any WordPress taxonomy to your WooCommerce product.

Taxonomy field type

Taxonomy field type

For example, let's attach to product T-Shirt with Logo product category taxonomy terms Clothing and Tshirts.

Taxonomy field inside product

Taxonomy field inside product

Now when searching for Clothing or Tshirts we will see T-Shirt with Logo product in search results.

Search for content inside product taxonomy field

Search for content inside the product taxonomy field

 

User Field

With user field type it is possible to attach any user to your product.

User field type

User field type

Lets add user wooteam to T-Shirt with Logo product.

User field inside product

User field inside product

Now when searching for wooteam user we will see T-Shirt with Logo product in search results.

Search for content inside product user field

Search for content inside the product user field


 

Grouped Fields

Grouped fields gives the option to combine several fields together. All ACF plugin fields that were added inside the field group will be available for search as usual fields ( Text, Text Area, Number, Email, URL, Wysiwyg Editor, Link, Post Object, Page Link, Relationship, Taxonomy, User ).

For example, lets create new fiel group with text and textarea fields inside.

Group field type

Group field type

Than lets add some content for this fields to T-Shirt with Logo product.

Group field inside product

Group field inside product

Now when searching for any of this custom content we will see T-Shirt with Logo product in search results.

Search for content inside the grouped fields

Search for content inside the grouped fields

 

Repeater

Repeater allows to create unlimited number of pre-defined fields groups inside the product.

For example, lets create repeater with text and textarea fields inside.

Repeater

Repeater

Than lets add some content for this fields to T-Shirt with Logo product.

Repeater fields inside product

Repeater fields inside product

Now when searching for any of this custom content we will see T-Shirt with Logo product in search results.

Search for content inside the repeater fields

Search for content inside the repeater fields