Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Collect search phrases when 'No results'
- This topic has 12 replies, 2 voices, and was last updated 9 years, 4 months ago by
Ernest Marcinko.
-
AuthorPosts
-
January 18, 2017 at 7:27 pm #11641
fespigado
ParticipantHi there,
I need to collect the phrases searched by users when the result is ‘No Result’ to later save it to a table.
I can not capture or use the trigger after the search.//add_filter( ‘asp_results’, ‘guardar_busqueda’, 1, 1 );
add_filter( ‘asp_ajax_results’, ‘guardar_busqueda’, 1, 2 );
//add_action( ‘asp_after_search’, ‘guardar_busqueda’, 10, 1);
//add_filter(‘asp_only_non_keyword_results’,’guardar_busqueda’);
add_action(‘woocommerce_single_product_summary’,’guardar_busqueda’,15);function guardar_busqueda($results) {
Global $wpdb;$user = wp_get_current_user();
if (empty($results[‘nores’])){
//if (!empty($results[‘nores’])){
var_dump ($results);
$wpdb->insert( wpt3_noresults,
array( ‘id_usuario’=> $user->ID,
‘nombre_usuario’ => $user->user_login,
‘busqueda’=> $s),
array(‘%s’,’%s’,’%s’));
if( ! $insert ) {
$wpdb->show_errors();}
}else{
$results = apply_filters( ‘asp_only_keyword_results’, $results );
foreach ($results as $k=>$v) {
$results[$k]->title = $results[$k]->title ;
}
}
return $results;
}Please I need help
January 23, 2017 at 2:11 pm #11685Ernest Marcinko
KeymasterHi!
I would recommend using this code skeleton to extend for the functionality:
[php]add_filter( ‘asp_after_search’, ‘guardar_busqueda’, 10, 2 );
function guardar_busqueda($s, $results) {
if ( empty($results) ) {
// No results, no keyword suggestions
} else if ( isset($results[‘keywords’]) ) {
// No results, but there are keyword suggestions
} else {
// There are results
}return $results;
}[/php]This way you can do different actions when there are no results, some keyword suggestions or results present 🙂
January 24, 2017 at 10:17 am #11700fespigado
ParticipantYou cannot access this content.
January 24, 2017 at 10:32 am #11702Ernest Marcinko
KeymasterI don’t think I understand the code here, for example why is this filter used:
[php]add_action( ‘woocommerce_single_product_summary’, ‘guardar_busqueda’, 15,2);[/php]
This is most likely incorrect and giving an error, as the ‘woocommerce_single_product_summary’ is executed on the bottom of the product with a single parameter, and without information of any search results or phrases, it’s not used for that.
Do you want to save the phrases on ajax search results, or when redirected to the results page? Because the code above only works for ajax results, not the results page. For the results page I rather recommend using the built in ‘post_results’ filter:
January 24, 2017 at 10:47 am #11703fespigado
ParticipantThanks for the quick reply.
Sorry for the code so dirty. I was trying to see that he gave me back the variables.
What I need is collect the searched words with no results or suggested words and insert in a table.Thank you
January 24, 2017 at 11:22 am #11704fespigado
ParticipantYou cannot access this content.
January 24, 2017 at 9:40 pm #11707fespigado
ParticipantYou cannot access this content.
January 25, 2017 at 11:26 am #11714fespigado
ParticipantMorning,Help me solve that problem. I have the customer waiting for this job.
Thank you
January 25, 2017 at 2:07 pm #11715Ernest Marcinko
KeymasterHi,
Please note that supports stands for fixing issues with the plugin mainly, and your requesting me to make a custom code for you, which is not part of this process. I can try to help as much as I can, but I cannot guarantee a custom code will work, you will have to verify it.
This code was working for me on a test table:
..and my test table looked like this:
If you need help with customizations or extending the plugin, I recommend wpkraken.io service. They are professionals, and does not outsorce the work to anyone.
January 25, 2017 at 10:52 pm #11728fespigado
ParticipantThank you very much for your attention.
I understand that the support is not for that. Just commenting, I have not asked you to write the code, since the first code I sent you was already well under way with some errors;-) Thank you very much for your attention. Right now I write a super positive rating on codecanyonJanuary 26, 2017 at 10:29 am #11730Ernest Marcinko
KeymasterYou are very welcome 🙂
Let me know if something is not clear, or not working, I’m more than happy to suggest possibilities if I can.
January 31, 2017 at 1:31 pm #11780fespigado
ParticipantThanks a lot for you help. It’s everything ok
January 31, 2017 at 3:16 pm #11781Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘Collect search phrases when 'No results'’ is closed to new replies.