igora100
Forum Replies Created
-
Hi @sander105
This is a very specific point. I was also puzzled by a similar search, but it was all to no avail.
Most likely, I will implement such functionality myself, since I will need that too.Forum: Plugins
In reply to: [Relevanssi - A Better Search] Show in which categories it was foundNow you have an array of object ID and term taxonomy ID pairs, and from that data you can easily count how many times each term taxonomy ID appears.
This was not enough, because In
wp_term_relationshipsthere are not only the product taxonomy terminals “product_cat”, I still had to attach bothwp_term_taxonomyand immediately joined thewp_termsto see the names of categories.
Thank you so much for your help !!! 🙂Forum: Plugins
In reply to: [Relevanssi - A Better Search] Show in which categories it was foundO, mighty and great Mikko !!!
I did it with your help!
It turned out such a request:$stringQ = "SELECT * FROM $wpdb->term_relationships tr "; $stringQ .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id=tt.term_taxonomy_id AND tt.taxonomy='product_cat') " ; $stringQ .= " LEFT JOIN {$wpdb->terms} t ON (t.term_id=tt.term_id) " ; $stringQ .= " WHERE tr.object_id IN ( " . implode( ',', $arr_find_ID ) . " )";At the output, I get an array of objects:
[10] => stdClass Object ( [object_id] => 442247 [term_taxonomy_id] => 23517 [term_order] => 0 [term_id] => 23517 [taxonomy] => product_cat [description] => [parent] => 23515 [count] => 398 [name] => Смартфоны [slug] => smartfony [term_group] => 0 )Next, I summarize the objects by
term_idand everything is ready!
The full time on the whole processing cycle (from the time of the formation of the found objects of the objects before the output of the formed table with the number of items found in each category) with 500 products found. It takes 0.01sec, which is very good and right 40 times faster!!! than usingget_the_terms ()Forum: Plugins
In reply to: [Relevanssi - A Better Search] Show in which categories it was foundI fulfilled such a request:
$args = [ 'taxonomy' => 'product_cat', 'hide_empty' => false, 'object_ids' => $arr_find_ID, ]; $Query_result = new WP_Term_Query($args);OR:
SELECT DISTINCT t.*, tt.* FROM wp_terms AS t LEFT JOIN wp_termmeta ON ( t.term_id = wp_termmeta.term_id AND wp_termmeta.meta_key='order') INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('product_cat') AND tr.object_id IN (437287, 442247, 437292, 437273 23755, 324303, 329711, 329821, 334945, 335027, 335618, 335945, 336112, 336114, 336508, 338523, 336726, 336791, 336803, 337167, 337168, 337434, 337477, 337502, 337551, 337596, 337772) AND ( ( wp_termmeta.meta_key = 'order' OR wp_termmeta.meta_key IS NULL ) )I very quickly was able to get all the categories in which the product was found, but …. I would also like to see how many products were found in one category or another (i.e. not how many total products in the category, but how many exactly were found!) … But I just can’t figure out how to do it …
Forum: Plugins
In reply to: [Relevanssi - A Better Search] Show in which categories it was foundRelevanssi doesn’t know which posts are in which category; it doesn’t need to. If you use a category filter in the search, the filtering is done in the database.
Many thanks, Mikko !
In this case, relavsis still works with its cashe, but does an additional request in the database or not?get all the categories for those posts directly from the wp_term_relationships database table
Thanks, I’ll try.
Hi, Mikko!
Sorry, my memory’s
Nothing wrong.
Indeed, it works great!
Have a nice day!Oh….
At the entrance of the relavanssi_compile_search_args () function, everything is fine!
Here we have:WP_Query Object ( [query] => Array ( [s] => камера [post_type] => product [product_cat] => bytovaya-tehnika ) [query_vars] => Array ( [s] => камера [post_type] => product [product_cat] => bytovaya-tehnika ... [tax_query] => Array ( [relation] => AND [0] => Array ( [taxonomy] => product_visibility [field] => term_taxonomy_id [terms] => Array ( [0] => 6 ) [operator] => NOT IN ) ) ..... [taxonomy] => product_cat [term] => bytovaya-tehnika ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [relation] => AND [0] => Array ( [taxonomy] => product_visibility [terms] => Array ( [0] => 6 ) [field] => term_taxonomy_id [operator] => NOT IN [include_children] => 1 ) [1] => Array ( [taxonomy] => product_cat [terms] => Array ( [0] => bytovaya-tehnika ) [field] => slug [operator] => IN [include_children] => 1 ) ) [relation] => AND [table_aliases:protected] => Array ( [0] => wp_term_relationships ) [queried_terms] => Array ( [product_cat] => Array ( [terms] => Array ( [0] => bytovaya-tehnika ) [field] => slug ) ) [primary_table] => wp_posts [primary_id_column] => ID ) ..... )But I have in
$query->query_vars['tax_query']something is, I do not know where it is ….. and it affects the result, because Next, in therelavanssi_compile_search_args ()functions, it is from$query->query_vars['tax_query'], and not from$query->tax_query, where I’m fine.I turned off all the plugins except the relavanssi plugin, the search does not take into account categories: (
I disabled Relevanssi Plugin – the search began to take into account categories.Is 6 the correct taxonomy ID number?
NO!. Coorect = 23166
Or is that some other taxonomy (like WooCommerce stock status)?
Seems to be yes.
It turns out the plugin does not receive additional selection criteria?
Tell me which function of which plugin file it happens, I will try to “catch” this moment.What if you try to use the product_cat ID number instead of the slug? Does that work any better?
Does not help.
SQL Query:
SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 0.75 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 0.75 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf FROM wp_relevanssi AS relevanssi WHERE relevanssi.term = 'камера' AND relevanssi.doc NOT IN ( SELECT DISTINCT(tr.object_id) FROM wp_term_relationships AS tr WHERE tr.term_taxonomy_id IN (6)) AND ( relevanssi.doc IN ( SELECT DISTINCT(posts.ID) FROM wp_posts AS posts WHERE posts.post_type IN ('product') ) ) ORDER BY tf DESC LIMIT 500Does the taxonomy parameter work in the Relevanssi admin search
YES!