Answer the question
In order to leave comments, you need to log in
How to add Wordpress taxonomy terms to search?
Guys, help me find a solution - it is necessary that the name and description of taxonomies get into the search results. That is, to search by the taxonomy terms themselves (fields - title, short description, custom field with an extended description), and not only by posts and pages. I tried to install the Ajax Search Pro advanced search plugin, but it didn't help either. Thanks in advance for your replies.
Answer the question
In order to leave comments, you need to log in
We'll have to dive into the wilds of the shit-coder. With WordPress, this is not so easy.
In short, you need to manually rewrite the sql query:
add_filter('posts_join', array(&$this, 'maginza_search_join' ));
add_filter('posts_where', array(&$this,'maginza_search_where' ));
add_filter('posts_groupby', array(&$this,'maginza_search_groupby'));
function maginza_search_join($join) {
global $wpdb;
if( is_search() ) {
$join .= 'LEFT JOIN '.Options::$table_meta.' ON wp_maginzameta.maginza_id=wp_posts.ID';
}
return $join;
}
function maginza_search_where( $where ) {
global $wpdb;
if( is_search() ) {
$findkeys='';
$where = preg_replace('/post_title LIKE \'(.*?)\'\)/', 'post_title LIKE \'$1\') OR ( (FIND_IN_SET(wp_maginzameta.meta_key, \''.$findkeys.'\')) AND (wp_maginzameta.meta_value LIKE \'$1\') ) ', $where );
}
return $where;
}
function maginza_search_groupby( $groupby ) {
if( !is_search() ) {
return $groupby;
}
$groupby="wp_posts.ID";
return $groupby;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question