• Resolved joelrhd

    (@joelrhd)


    I really like this plugin. Just want to know if I can include ACF custom fields values when searching?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ishitaka

    (@ishitaka)

    By default, only the “full_text_search_search_text” field is searched. The value of the text field named “full_text_search_search_text” in ACF is searched.
    Other fields must be customized with PHP code.

    Thread Starter joelrhd

    (@joelrhd)

    @ishitaka Thank you for your time replying. For the other fields – Can be done with PHP code..Do we have to use a hook from this plugin? Can you please give me an example. Is it capable of searching as well inside ACF File field? Thanks!

    Plugin Author ishitaka

    (@ishitaka)

    The code below will allow the ACF fields (my_text and my_file) to be searched.

    add_filter( 'full_text_search_index_post', function( $data, $post_ID ) {
    	global $full_text_search;
    
    	if ( $full_text_search ) {
    		if ( 'post' === $data['post_type'] ) {
    			if  ( function_exists( 'get_field' ) ) {
    
    				$keywords = $data['keywords'];
    
    				// Text
    				$my_text = get_field( 'my_text', $post_ID );
    				if ( $my_text ) {
    					$keywords .= "\n" . $my_text;
    				}
    
    				// PDF file (File ID)
    				$my_file_id = get_field( 'my_file_id', $post_ID );
    				if ( $my_file_id ) {
    					$keywords .= "\n" . get_post_meta( $my_file_id, 'full_text_search_search_text', true );
    				}
    
    				$data['keywords'] = trim( $keywords );
    			}
    		}
    	}
    	return $data;
    }, 10, 2 );

    * The full_text_search_index_post filter hook has been added since version 2.6.0.

    Place this code in your child theme’s functions.php and regenerate your index.

    Plugin Author ishitaka

    (@ishitaka)

    We haven’t heard back from you in a while. I’ve gone ahead and marked this thread as resolved.
    If the problem is not solved yet, please open a new thread.
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can it include custom fields generated from ACF plugin?’ is closed to new replies.