Search Element "BUG" NOT Resolved in Dec 2018 Update

Hey Guys,

I was disappointed that the Search Element ‘BUG’ was not included into the Dec 2018 Cornerstone update. Any idea when this will happen, as my entire website requires users to search certain almost 1,100 employers and they are unable to and I wish to launch my website mid January 2019. Below are my messages to ThemeCo about this for your consideration.


RueNel
Staff
24d

Hello Simon,

I have investigated this issue and I can confirmed that none of the text or headline text element is searchable which is a bug in this latest release. This is because the content of the element does not resides in the post description contents. It is directly stored in the post meta which will only gets displayed when the text or headline element is rendered in the front end.

I would recommend that you use classic custom headline and classic text element instead. Meanwhile, I’ve submitted this to our issue tracker so the developers will be made aware of it. Once they’ll have a fix, it will be updated and will be rolled out in the next release update cycle.

Thanks you for your understanding.


Good_Usernames_Gone
23d

Thank you for your reply RueNel.

It would take me 80+ hours of work to change text to classic text + Header for 1,100 employer listings and will wait for the next update cycle to be released to fix this.

Any idea ‘approximately’ when this next release will happen?

Cheers,

Simon

Hey Simon,

I’m sorry if you have expected this but we do not have a timeline as to when the V2 elements would be searchable. For now, you will need an externally powered search engine that will search the frontend contents rather than the WordPress content.

There are also third party search solutions available like SearchWP and FacetWP to give you more search controls.

Thank you for understanding.

Hello Simon,

One temporary solution is to add the code below to your child theme’s functions.php file.

add_filter( 'posts_join', 'themeco_search_join', 10, 2 );
add_filter( 'posts_groupby', 'themeco_search_groupby', 10, 2 );
add_filter( 'posts_where', 'themeco_search_where', 10, 2 );

function themeco_search_join( $join, $wp_query ) {

   global $wpdb;

   if( is_search() && !is_admin() && $wp_query->is_main_query() ) {
      $join .= "LEFT JOIN $wpdb->postmeta AS m ON ($wpdb->posts.ID = m.post_id) ";
   }

   return $join;

}

function themeco_search_groupby( $groupby, $wp_query ) {

   global $wpdb;

   if( is_search() && !is_admin() && $wp_query->is_main_query() ) {
      $groupby = "$wpdb->posts.ID";
   }

   return $groupby;

}


function themeco_search_where( $where, $wp_query ) {

global $wpdb;

if( is_search() && !is_admin() && $wp_query->is_main_query() ) {
   
    $args = array(
        'public'            => true,
        'exclude_from_search'    =>  false
    );

   $post_types = get_post_types( $args );
   $post_types = "'" . implode( '\', \'', $post_types ) . "'";
   
   $where = "";
        $search_terms = se_themeco_get_search_terms();
        $n = !empty($wp_query->query_vars['exact']) ? '' : '%';
        $searchand = '';
        if (count($search_terms) < 1) {
                // no search term provided: so return no results
                $search = "1=0";
        } else {
                foreach( $search_terms as $term ) {
                        $term = esc_sql( like_escape( $term ) );
                        $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}') OR (m.meta_value LIKE '{$n}{$term}{$n}'))";
                        $searchand = ' AND ';
                }
        }
        $where .= " AND ${search} ";
        $where .= " AND ($wpdb->posts.post_password = '') ";
        $where .= " AND ($wpdb->posts.post_type IN ($post_types)) ";
        $where .= " AND ($wpdb->posts.post_status = 'publish') ";
}

return $where;

 }

  // Code from Search Everywhere plugin
  function se_themeco_get_search_terms()
 {
    global $wpdb, $wp_query;
    $s = isset($wp_query->query_vars['s']) ? $wp_query->query_vars['s'] : '';
    $sentence = isset($wp_query->query_vars['sentence']) ? $wp_query->query_vars['sentence'] : false;
    $search_terms = array();

    if ( !empty($s) )
    {
            // added slashes screw with quote grouping when done early, so done later
            $s = stripslashes($s);
            if ($sentence)
            {
                    $search_terms = array($s);
            } else {
                    preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
                    $search_terms = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
            }
    }
    return $search_terms;
}

This code will not alter the database but only enhances the search functionality to include the content of a Cornerstone-created (Pro-created) post/page.

Thank you for your response Christian and I have already tried 2 or 3 other 3rd party search plugin’s based on another person at THEMCO’s suggestion without success. I have not tried who you have suggested and will give it a try…

Hey @Good_Usernames_Gone,

Ben is one of our developers. His work around should work as a temporary fix for the situation for the moment.

Thank you for your understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.