Add ACF field to searchable for page content
-
Hi guys,
Currently, I can add ACF fields to searchable for custom post type. However, I’m also using ACF fields for custom page templates ( post type = page ), most of page content is in ACF fields. I want to these ACF fields value to searchable for page, but it doesn’t work. My code as below. I’m not sure this correct way to do. Can you help me!add_filter( 'algolia_post_shared_attributes', 'cwy_algolia_page_attributes', 10, 2 ); add_filter( 'algolia_searchable_post_shared_attributes', 'cwy_algolia_page_attributes', 10, 2 ); function cwy_algolia_page_attributes( array $attributes, WP_Post $post ) { $searchable_post_types = ['page']; if ( !in_array($post->post_type,$searchable_post_types) ) { return $attributes; } //Add acf fields to searchable for post type = page $attributes['aboutus_title'] = strip_tags(get_field( 'aboutus_title', $post->ID )); $attributes['aboutus_desc'] = strip_tags(get_field( 'aboutus_desc', $post->ID )); $attributes['aboutus_sec1_title'] = strip_tags(get_field( 'aboutus_sec1_title', $post->ID )); $attributes['aboutus_sec1_desc'] = strip_tags(get_field( 'aboutus_sec1_desc', $post->ID )); } add_filter( 'algolia_posts_page_index_settings', 'cwy_page_index_settings' ); function cwy_page_index_settings( array $settings ) { $settings['attributesToIndex'][] = 'unordered(aboutus_title)'; $settings['attributesToSnippet'][] = 'aboutus_title:50'; $settings['attributesToIndex'][] = 'unordered(aboutus_desc)'; $settings['attributesToSnippet'][] = 'aboutus_desc:50'; $settings['attributesToIndex'][] = 'unordered(aboutus_sec1_title)'; $settings['attributesToSnippet'][] = 'aboutus_sec1_title:50'; $settings['attributesToIndex'][] = 'unordered(aboutus_sec1_desc)'; $settings['attributesToSnippet'][] = 'aboutus_sec1_desc:50'; // Always return the value we are filtering. return $settings; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Add ACF field to searchable for page content’ is closed to new replies.