Home Forums Add-ons Flexible Content Field Include flexible fields to site search Reply To: Include flexible fields to site search

  • hope i understand you right. (i had done core search ability by a workaround)
    if you dont use the normal content field of WP, then you could try something like that:

    function my_acf_update_text($post_id) {
    if( have_rows('my_custominhalt') ):
         // loop through the rows of data
    	while ( have_rows('my_custominhalt') ) : the_row();
    	        if( get_row_layout() == 'text-block' ){
    	        $my_subtitle = get_sub_field('my_subtitle');        
    	        $my_content = get_sub_field('my_text_content');
    	        $my_search = '<h3>'.$my_subtitle.'</h3><p>'.$my_content.'</p>';
    	        if( get_row_layout() == 'text-image-block' ){
    	        $my_subtitle = get_sub_field('my_subtitle');        
    	        $my_content = get_sub_field('my_imagetext');
    	        $my_search = '<h3>'.$my_subtitle.'</h3><p>'.$my_content.'</p>';       
    		$my_search_full = $my_search_full.' '.$my_search;
    	// update post with the post_content created from 
    	$my_post = array('ID'=> $post_id,'post_content' => $my_search_full);
    remove_action('save_post', 'my_acf_update_text');
    wp_update_post( $my_post );
    add_action('save_post', 'my_acf_update_text');
    add_action('save_post', 'my_acf_update_text');

    place it into your plugin, or functions.php
    what it does : it create a action that loop through all flexible fields with text, and save them to post_content. thanks to that i am able to search content by core function.

    hope that help you too (of course you need to adjust it to fit your needs)
    be careful, it overwrite anything inside post_content(core-wysiwyg of WP)
    you also need to re-save every post before it works, because only after save content is inserted into post_content

    if you need core-wysiwyg, then create a additional field and save the loop into that field. basically it would be easier to search only inside a single field instead of a repeater/flexible field