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

  • 0 Votes
    2 Posts
    103 Views
    EpsilonAdminE

    Hi @Simply_Friend

    Thank you for the question. Actually it's not planned to be added to the plugin core, because this feature (search by date FROM - TO) is already implemented in WP Native search (in WP_Query()).

    So you can search with date using WP_Query parameter date_query.

    Here is the topic: https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

    Another question is if you want date picker fields to be added next to the text query field in the search widget.

    This is fairly easy to do for the average WP developer. There are probably some visual constructors to do this, but I can’t recommend anything here - if you find a solution, please write. It will be useful for other users.

    We don't plan to add a search form builder to the core functionality of WPFTS because we don't want to compete with Elementor / Beaver Builder / Visual Builder etc etc, although we will probably do a detailed tutorial on how to use the builders to make a search widget with additional fields.

    Hope this helped you.

    Thanks!

  • how to add buttons to the search engine

    Frequently Asked Questions
    5
    1 Votes
    5 Posts
    472 Views
    EpsilonAdminE

    @guarani23 Can you send me access to your website to the private messages? I can make a code, it's really simple.

  • DB table size?

    Frequently Asked Questions
    6
    0 Votes
    6 Posts
    606 Views
    EpsilonAdminE

    Hi @ALG1970

    Yes, it was another bug.

    I've just updated the plugin to version 1.59.211 that should fix the issue.

    The "_tp" table should not grow anymore.

    Also this should not make any additional load to the server.

    Please update WPFTS and give it another chance.

    Thank you, let me know if this goes fine now.

  • WPML compatibility

    Frequently Asked Questions
    1
    0 Votes
    1 Posts
    546 Views
    No one has replied
  • 0 Votes
    2 Posts
    757 Views
    EpsilonAdminE

    Hi, @wonderbuild

    Should be you are using the "WPFTS :: Live Search" widget. This widget is intended to show this live search data. If you don't want them, simply use the native WP Search widget.

    Hope it helps.

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