Fitoussi / geo-my-wp

Advanced mapping and geolocation plugin for Wordpress
https://geomywp.com
36 stars 22 forks source link

search by tag #66

Open artmediastudio opened 4 years ago

artmediastudio commented 4 years ago

I tried to implement search by tag other than by title and description. so I did it remove_filter( 'posts_where', 'gmw_ps_pt_query_keywords', 20 ); add_filter( 'posts_where', 'gmw_ps_pt_query_keywords_tags', 20, 2 );

if ( ! apply_filters( 'gmw_ps_disable_keywords_content_search', false ) ) { $query .= " OR {$wpdb->posts}.post_content LIKE '{$like}' OR {$wpdb->posts}.post_excerpt LIKE '{$like}'"; }

   // search tag

    $query .=" OR (";
    $query .=" {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id ";
    $query .=" AND {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id ";
    $query .=" AND {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id ";
    $query .=" AND {$wpdb->terms}.name LIKE '{$like}'";
    $query .= ")";

$where .= " AND ({$query})";

but i have this error Errore sul database di WordPress: [Unknown column 'wp_term_relationships.object_id' in 'where clause'] SELECT SQL_CALC_FOUND_ROWS wp_posts.*, gmw_locations.ID as location_id, gmw_locations.object_type, gmw_locations.object_id, gmw_locations.user_id, gmw_locations.latitude as lat,gmw_locations.latitude, gmw_locations.longitude as lng,gmw_locations.longitude, gmw_locations.street_name, gmw_locations.street_number, gmw_locations.street, gmw_locations.premise, gmw_locations.city, gmw_locations.region_name, gmw_locations.region_code, gmw_locations.postcode, gmw_locations.country_name, gmw_locations.country_code, gmw_locations.address, gmw_locations.formatted_address FROM wp_posts LEFT JOIN wp_gmw_locations gmw_locations ON wp_posts.ID = gmw_locations.object_id AND gmw_locations.object_type = 'post' WHERE 1=1 AND wp_posts.post_type IN ('product', 'convenzione') AND ((wp_posts.post_status = 'publish')) AND (wp_posts.post_title LIKE '%centro%' OR wp_posts.post_content LIKE '%centro%' OR wp_posts.post_excerpt LIKE '%centro%' OR ( wp_posts.ID = wp_term_relationships.object_id AND wp_terms.term_id = wp_term_taxonomy.term_id AND wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id AND wp_terms.name LIKE '%centro%')) AND (wp_posts.post_title LIKE '%centro%' OR wp_posts.post_content LIKE '%centro%' OR wp_posts.post_excerpt LIKE '%centro%') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5 If i change manually the query from

FROM wp_posts LEFT JOIN to

FROM wp_term_relationships,wp_terms,wp_term_taxonomy, wp_posts LEFT JOIN

It works. How can change with FROM field of query ? I tried to set $clauses['from'] but it dind' t work. Thnaks