Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search by tag #66

Open
artmediastudio opened this issue Sep 17, 2019 · 0 comments
Open

search by tag #66

artmediastudio opened this issue Sep 17, 2019 · 0 comments

Comments

@artmediastudio
Copy link

artmediastudio commented Sep 17, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant