Get WPFTS Pro today with 25% discount!

Problem with ACF generated fields


  • Hi,

    I work on a design, I build from the ground up for a special project. (This means, the theme won't be available anywhere else...)

    In this theme I work with a lot of custom post types and custom fields (generated by ACF)

    Since acf fields aren't using post_meta but are only available via get_field('<fieldname>'), and I don't want to write new lines of code for every field into the functions.php I changed the routine you suggest in your Documentation like this:

    add_filter('wpfts_index_post', function($index, $post) {
    	
    	global $wpdb;
    	
    	$index[get_post_type()] = implode(' ',get_fields($post->ID));
    	
    	return $index;
    	
    }, 3, 2);
    

    It seems to work. In the SandBox at least. When I type in there a searchterm which can only be found in one of those custom fields, I get the correct results in the TestSearch Area.
    But I do get a "nothing can be found" non-result when I try to find the term using the search.php. The title of one of the custom posts creates the right result, but not the the entry from the custom field.

    Here is my search.php (it isn't really designed yet, it's just for proof of concept...)

    	$s=get_search_query();
    	$args = array(
                    's' =>$s
                );
        // The Query
    $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) {
            _e("<h2 style='color:#1c1c1c'>Search Results for: ".get_query_var('s')."</h2>");
            while ( $the_query->have_posts() ) {
               $the_query->the_post();
                     ?>
                        <li>
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        </li>
                     <?php
            }
        }else{
    ?>
            <h2 style='color:#1c1c1c'>Nothing Found</h2>
            <div class="alert alert-info">
              <p>Sorry, but nothing matched your search criteria. Please try again with some different keywords.</p>
    	</div></main>
    <?php } 
     
    
    

    What can I do?

    Best
    Martin


  • Hi @dornfeld

    Basically, you should not call WP_Query again inside the search.php because WP is calling this template automatically AFTER the main query is executed.

    By default, the WPFTS is applied to the main query only (to avoid interference with other plugins and themes), but you can force WPFTS usage in your custom WP_Query calls too.

    The solution for you is:

    1. You can remove your own WP_Query() call and the respective code and use standard WP methods.

    2. You can add the parameter "wpfts_is_force => 1" to your WP_Query() parameters to force WPFTS execution.

    Also, in case you don't use the main query, the Smart Excerpts will be also disabled. To force them, please add these two lines before have_posts() (before the loop, only once)

    global $wpfts_core;
    
    $wpfts_core->ForceSmartExcerpts(isset($_GET['s']) ? $_GET['s'] : '');
    

    Hope this will help.


  • @epsilonadmin

    Thanks!

    It does!!! It works.

    Thanks for your hard work!!!

Suggested Topics

Be the first to read the news!

We are always improving our products, adding new functions and fixes. Subscribe now to be the first to get the updates and stay informed about our sales! We are not spammy. Seriously.

Join Us Now!

We are a professional IT-team. Many of us have been working in a Web IT field for more than 10 years. Our advanced experience of software development has been employed in the creation of the WordPress FullText Search plugin. All solutions implemented into the plugin have been used for 5 or more years in over 60 different web-projects.

We are looking forward to your comments, requests and suggestions in relation to the current plugin and future updates.

ewm-logo-450

The forum powered by NodeBB | Contributors