Adjusting the search engine

Posted in: Newspaper
Post count: 101

Hi,

I am currently trying to make the search engine also look in the custom fields made with ACF.

However, after downloading ACF better search plugin, values from those fields still won’t show up.
Also, adding the following code as a plugin doesn’t do the trick.

/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;

if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}

return $join;
}
add_filter('posts_join', 'cf_search_join' );

/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*/
function cf_search_where( $where ) {
global $pagenow, $wpdb;

if ( is_search() ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}

return $where;
}
add_filter( 'posts_where', 'cf_search_where' );

/**
* Prevent duplicates
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*/
function cf_search_distinct( $where ) {
global $wpdb;

if ( is_search() ) {
return "DISTINCT";
}

return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );

So I was wondering, the search engine that is used in the theme, I take it it’s not the standard wordpress search function ?

And how would I implement the above code best ?

Post count: 35449

Hi,

Please note that we do not test the ACF plugin with our theme, and we can not provide support for plugins that we did not tested with our theme, sorry.

Also please not that the search from our theme is the search from WordPress only that our theme make some improve using ajax.

Thank you!

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.