PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Adding tag name taxonomy in the search by text

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi, I’m looking for the sql code in which the products are selected through by_text extension.

I’m trying to add the code to do something similar to this:

'title_or_content_or_excerpt_or_tag' => 'Search by title OR content OR excerpt OR tag',

I want that the search by_text select also the products that have similar tags
So i made a sql query, whit the where like yours from here:


case 'title_or_content_or_excerpt':
$text_where .="  (( LOWER(post_title) REGEXP '{$woof_text}') OR ( LOWER(post_excerpt) REGEXP '{$woof_text}') OR ( LOWER(post_content) REGEXP '{$woof_text}'))";
break;

The sql query is this:
(it works just fine)


SELECT p.*
FROM efr_posts AS p
JOIN efr_term_relationships AS tr ON p.id = tr.object_id
JOIN efr_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN efr_terms AS t ON tt.term_id = t.term_id
WHERE t.slug LIKE '%text%' OR (( LOWER(post_title) REGEXP '[[:<:]]text[[:>:]]') OR ( LOWER(post_excerpt) REGEXP '[[:<:]]text[[:>:]]') OR ( LOWER(post_content) REGEXP '[[:<:]]text[[:>:]]')) AND p.post_type LIKE 'product'

Where can i add this 3 line?


JOIN efr_term_relationships AS tr ON p.id = tr.object_id
JOIN efr_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN efr_terms AS t ON tt.term_id = t.term_id

The where part is here:


case 'title_or_content_or_excerpt_or_tag':
$text_where .=" (( LOWER(post_title) REGEXP '{$woof_text}') OR ( LOWER(post_excerpt) REGEXP '{$woof_text}') OR ( LOWER(post_content) REGEXP '{$woof_text}'))";
break;

Any suggestion?
Thanks!

Hello

I  answered  you  on  wordpress.org

On Wordpress.org the answers given did not lead to a resolution of the problem.

I purposely purchased the license to get clearer support on this issue.

I don't understand how complicated it can be to add a trivial search even in product tags when searching by text.

I have already added the admin side setting, the case in the php switch, and you still can't tell me where I can insert the JOIN.

The problem is simple, I think the solution is the same.
Also the taxonomy in pre_get_post doesn't work.

https://pastebin.com/WSKWX5CQ

Hello

Paste your license key here - https://c2n.me/43SC6rb.png -> https://c2n.me/42HBIt7.png

Customization of the code is not included in the support.

I already wrote to you about this. This plugin uses standard WP_Query.  For this reason, I use a standard hook"post_where" for text search.  For this reason, I advise you to use a standard hook -"posts_join" ( https://developer.wordpress.org/reference/hooks/posts_join/ )  - This plugin does not have a secret place where you can change the SQL query.

https://c2n.me/47msWZ3.png -"posts_join" - this hook passes wp_query so you can always find out what request it is + check the GET request

I also offered you an alternative solution - https://c2n.me/47msNBP.png

Let's recap.
Use the WP_Query standard. But is he never called back?
I have looked your code and there is no point where WP_Query is being called.
The only times I've seen a wp_query are inside the Ajax search and inside the parse_query() function.

I tried to use the post_join hook, but the usual question of where to put it remains.
There, too, all changes made to the code are made in vain as they are not done with the correct documentation from you.

function txt_search_join($join){
global $wpdb;
if (is_search())
$join
.= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
return $join;
}

I placed it both inside the by_text\index.php and inside your function with no results.
Also of course as soon as I change the text_where the search returns 0 results.

I can suggest another method: in the function of my plugin add a separate search query( https://c2n.me/47hvJF3.png ) – and add to $text_where resul like post__in or ID=result_ids

By adding an alternative search function I break Woofs.
At this point we might as well use the classic Woocommerce search but search only by product name is useless for me because the publishers insert the text inside the tags to increase the searchability.
I rely on you to find a simple and effective solution that does not involve having to destroy the site or theme.

I also attach the parse_tax_query that doesn't work.

Spoiler

function efru_pre_get_query($wp_query)
{
    if (isset($_GET['woof_text'])) {
        $terms = sanitize_text_field($_GET['woof_text']);
        $wp_query->tax_query->relation = 'OR';
        $wp_query->tax_query->queries[0] = array(
            'taxonomy' => 'product_tag',
            'field' => 'slug',
            'terms' => array($terms),
            'operator' => 'IN',
        );
    }
}
add_action('parse_tax_query', 'efru_pre_get_query');

Hello

You can see a hook"post_where" in my code - this is part of the standard wp_query! My plugin does not use native SQL queries where you can insert your JOIN

 but the usual question of where to put it remains. -  But this is the hook that applies to wordpress. It doesn’t depend on my plugin! You can embed it in functions.php or in your own plugin

How  to  use  hooks - https://developer.wordpress.org/plugins/hooks/

By adding an alternative search function I break Woofs. - in this case you need more programming experience. Or give me a screenshot with your code, I can check it

Sorry, I do not want to offend you, but it seems to me that you do not have enough experience to accomplish this task. You should read the Wordpress documentation or hire a developer

OR  try  this  extension - https://products-filter.com/extencion/quick-search/  - this is a separate filter that has such a feature

Hello,

This pastebin contains the first 2 functions that I tried to use inside my functions.php to insert myself into pre_get_post or parse_tax_query, unfortunately they don't work, I can't get the desired result, which would be to make sure that a search via text return not only products with that word in the title, but also in tags in order to increase results.

You advised me to use wordpress hooks 'post_join' to hang on to your wp_query and add my joins.
The code that I tried to add, always to the functions.php is the following:

Unfortunately, this change also does not work.
The code in $text_where is as follows:


(Line 258 is in a comment to prevent no results.)
Adding text_where always results in search results equal to 0.

I am however interested in understanding this research here -> https://c2n.me/47msNBP.png

Don't you have any"piece of code" from which I can start to insert it?
But without overwriting the various filters offered by the plugin.

Hello

Let's try with the simplest solution.

Please try this  extension -  https://products-filter.com/extencion/quick-search/  - it can do a text search on all taxonomies!

About  your code:

https://c2n.me/47oGDgt.png - note that the search is by slug and not by title

https://c2n.me/47oGYgo.png -  You should pass all arguments

https://c2n.me/47oHgBv.png - here should be a comparison operator

Don't you have any"piece of code" from which I can start to insert it? - you can use this code as an example: https://c2n.me/47oHvra.png

 

 

Good morning,

I apologize for the previous misunderstandings.
I have corrected the parts indicated by you and now it works!

Through posts_request I managed to intercept the real sql request (I enclose below in a pastebin)

The last problem is this part of the sql that I can't understand where it is generated:

AND efr_posts.ID IN (13438,12674,6356,14180,12928,7551,8390,10620,9614)

this piece of query invalidates the changes, while instead if I take it off on phpMyAdmin I can get the desired results.
Is this a sql generated by wp_query?

Hello

my plugin can add this part of the request in only these places

wp-content\plugins\woocommerce-products-filter\ext\by_sku\index.php - https://c2n.me/47q7sPH.png

AND

wp-content\plugins\woocommerce-products-filter\ext\by_onsales\index.php - https://c2n.me/47q7XPH.png

this code will work if you filter  by SKU or by Sale

 

I confirm that it works.
Thanks a lot, I apologize for the confusion and insistence, but it was an important change!
Thanks again!
I attach the file by_text / index.php for the final result.
https://pastebin.com/T52wnmLu

Hello

Great!  Welcome;)