i have search field on page default wp field think. when hit search button searching posts
table , show results.
now want join second table search , show results there if there any.
so in function.php
file in theme folder have added this:
function vh_search_meta_data_join($join) { global $wpdb; // join post meta table if performing search if ( get_query_var( 's' ) == '' ) { return $join; } // join post meta table if on contacts custom post type if ( !in_array('videogallery', get_query_var( 'post_type' ) ) ) { return $join; } // join post meta table $join .= " left join ".$wpdb->prefix."hdflvvideoshare"; return $join; } function vh_search_meta_data_where($where) { global $wpdb; // join post meta table if performing search if ( get_query_var( 's' ) == '' ) { return $where; } // join post meta table if on contacts custom post type if ( !in_array('videogallery', get_query_var( 'post_type' ) ) ) { return $where; } // start of query, ' , ((', , rest of query $startofquery = substr( $where, 0, 7 ); $restofquery = substr( $where ,7 ); // inject our clause in between start of query , rest of query $where = $startofquery . "(" . $wpdb->prefix."hdflvvideoshare.description '%" . get_query_var( 's' ) . "%') or " . $restofquery ." group " . $wpdb->posts . ".id"; // return revised clause var_dump($where); return $where; }
when add doesn't return neither posts nor hdflvvideoshare. it's showing me "no results"
.
var_dump($where);
return this:
string(625) " , (((wpdu_hdflvvideoshare.description '%driver%') or (((wpdu_posts.post_title '%driver%') or (wpdu_posts.post_content '%driver%'))) or ((tter.name '%driver%')) or ((tter.slug '%driver%')) or ((ttax.description '%driver%')) or ((m.meta_value '%driver%')) or ((wpdu_posts.post_excerpt '%driver%')) or (((cmt.comment_content '%driver%')) , cmt.comment_approved = '1') or ((u.display_name '%driver%')) )) , (wpdu_posts.post_password = '') , wpdu_posts.post_type in ('page', 'post', 'videogallery') , (wpdu_posts.post_status = 'publish') group wpdu_posts.id" string(541) "(((wpdu_posts.post_title '%driver%') or (wpdu_posts.post_content '%driver%'))) or ((tter.name '%driver%')) or ((tter.slug '%driver%')) or ((ttax.description '%driver%')) or ((m.meta_value '%driver%')) or ((wpdu_posts.post_excerpt '%driver%')) or (((cmt.comment_content '%driver%')) , cmt.comment_approved = '1') or ((u.display_name '%driver%')) )) , (wpdu_posts.post_password = '') , wpdu_posts.post_type in ('page', 'post', 'videogallery') , (wpdu_posts.post_status = 'publish')"
what wrong. why can't work?
update: i believe full query generated
select distinct sql_calc_found_rows wpdu_posts.* wpdu_posts left join wpdu_hdflvvideoshare left join wpdu_term_relationships trel on (wpdu_posts.id = trel.object_id) left join wpdu_term_taxonomy ttax on ( ( ttax.taxonomy = 'category' or ttax.taxonomy = 'post_tag' or ttax.taxonomy = 'post_format' or ttax.taxonomy = 'bp_member_type' or ttax.taxonomy = 'bp-email-type' ) , trel.term_taxonomy_id = ttax.term_taxonomy_id) left join wpdu_terms tter on (ttax.term_id = tter.term_id) left join wpdu_comments cmt on ( cmt.comment_post_id = wpdu_posts.id ) left join wpdu_postmeta m on (wpdu_posts.id = m.post_id) left join wpdu_users u on (wpdu_posts.post_author = u.id) 1=1 , ( ( (((wpdu_hdflvvideoshare.description '%driver%') or (((wpdu_posts.post_title '%driver%') or (wpdu_posts.post_content '%driver%'))) or ((tter.name '%driver%')) or ((tter.slug '%driver%')) or ((ttax.description '%driver%')) or ((m.meta_value '%driver%')) or ((wpdu_posts.post_excerpt '%driver%')) or (((cmt.comment_content '%driver%')) , cmt.comment_approved = '1') or ((u.display_name '%driver%')) )) , (wpdu_posts.post_password = '') , wpdu_posts.post_type in ('page', 'post', 'videogallery') , (wpdu_posts.post_status = 'publish' or wpdu_posts.post_type = 'attachment' or wpdu_posts.post_status = 'draft') group wpdu_posts.id) , post_type != 'revision') , post_status != 'future' order wpdu_posts.post_title '%driver%' desc, wpdu_posts.post_date desc limit 0, 10
your query has group by
condition inside where
clause. there may other issues, ensure syntax error.
Comments
Post a Comment