Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

t-servi.com on "hook to query the post_meta"

$
0
0

Hello,
I looking for the hook that can allow me to add some results of the post_meta table for a search query. I'll already try the pre_get_post and I write this code in a plugin:

function search_filter($query) {
  if ( !is_admin() && $query->is_search() ) {
  $s = get_search_query();
  global $wpdb;
  $querystr = "
        SELECT $wpdb->posts.*
        FROM $wpdb->posts INNER JOIN $wpdb->postmeta
        ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
        WHERE 1=1 AND ((($wpdb->posts.post_title LIKE '%$s%')
        OR ($wpdb->posts.post_content LIKE '%$s%')))
        AND $wpdb->posts.post_type = 'post'
        OR ($wpdb->posts.post_status = 'publish')
        AND ( ($wpdb->postmeta.meta_key = '_city_box'
        AND CAST($wpdb->postmeta.meta_value AS CHAR)
        LIKE '%$s%') ) GROUP BY $wpdb->posts.ID
        ORDER BY $wpdb->posts.post_title
        LIKE '%$s%' DESC,
        $wpdb->posts.post_date
        DESC";
      $pageposts = $wpdb->get_results($querystr, OBJECT);
    }
}
add_action('pre_get_posts','search_filter');

but when I look in the search.php page and try var_dump($wp_query->request)
the result of the var_dump don't give me the query I write.
Sorry for my missunderstood of wordpress. Can you help me?
Thank you.
Jean.


Viewing all articles
Browse latest Browse all 8245

Trending Articles