0
For example, I search PAGODE in the search, above the results of the posts appears also the categories that has the name PAGODE.
I tried that: include tag and category in wordpress search results
but I couldn’t. Someone to help me ?
0
For example, I search PAGODE in the search, above the results of the posts appears also the categories that has the name PAGODE.
I tried that: include tag and category in wordpress search results
but I couldn’t. Someone to help me ?
1
A good option is to install the plugin Relevanssi. It has settings to help with your problem, and also greatly improves the quality of searches.
0
I GOT IT WITH THAT CODE!
$search_term = explode( ' ', get_search_query( false ) );
global $wpdb;
$select = "
SELECT DISTINCT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('category')";
$first = true;
foreach ( $search_term as $s ){
if ( $first ){
$select .= " AND (t.name LIKE '%s')";
$string_replace[] = '%'.$wpdb->esc_like( $s ).'%';
$first = false;
}else{
$select .= " OR (t.name LIKE '%s')";
$string_replace[] = '%'. $wpdb->esc_like( $s ).'%';
}
}
$select .= " ORDER BY t.name ASC";
$terms = $wpdb->get_results( $wpdb->prepare( $select, $string_replace ) );
if ( count($terms) > 0 ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li><a href="'.esc_url( get_term_link( $term ) ).'" title="'.esc_attr( $term->name ).'">' . esc_html( $term->name ) . '</a></li>';
}
echo '</ul>';
}
Browser other questions tagged php wordpress
You are not signed in. Login or sign up in order to post.