Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › asp_query_args IS NOT WORKING
- This topic has 6 replies, 2 voices, and was last updated 6 years, 4 months ago by
Ernest Marcinko.
-
AuthorPosts
-
January 21, 2020 at 1:45 pm #25363
essenciadigital74
ParticipantHi!
I have 3 searches in the website. The first one is to search Users, the second is to search any content (Post) inside any categorie and the third which search specifics posts inside specifics categories…To the last search work I have to pass some args, so I use this ‘add_filter(“asp_query_args”, “asp_query_args_change”, 1, 3);’ and pass my custom params inside the function “asp_query_args_change”.
It was working but it stopped, I thought were something inside custom function but it does not enter in the function, so I want to know if there is some update to do or something similar that can help me.
Thank you!
January 21, 2020 at 1:54 pm #25364Ernest Marcinko
KeymasterHi,
There was no change whatsoever regarding that hook. Can you please paste the function with the hook here? I would like to validate it.
January 21, 2020 at 1:57 pm #25365essenciadigital74
Participantadd_filter("asp_query_args", "asp_query_args_change", 1, 3); function asp_query_args_change($args, $search_id) { $post_id = get_string_between($_POST['options'], "current_page_id=", "&qtranslate_lang"); if($search_id == 3) { $args['post_type'] = array('post'); $args['post_fields'] = array('title', 'content', 'excerpt', 'terms'); $args['post_tax_filter'] = array( array( 'taxonomy' => 'category', 'include' => wp_get_post_categories($post_id) ) ); } return $args; } function get_string_between($string, $start, $end){ $string = ' ' . $string; $ini = strpos($string, $start); if ($ini == 0) return ''; $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); }-
This reply was modified 6 years, 4 months ago by
Ernest Marcinko.
January 21, 2020 at 2:21 pm #25368Ernest Marcinko
KeymasterHi,
Well, there are a few unneccesary lines there, as well as I am not sure the the wp_get_post_categories returns the array of category IDs by default. Try this modification:
add_filter("asp_query_args", "asp_query_args_change", 10, 2); function asp_query_args_change($args, $search_id) { $post_id = $args['_page_id']; if ($search_id == 3) { $args['post_type'] = array('post'); $args['post_fields'] = array('title', 'content', 'excerpt', 'terms'); $args['post_tax_filter'] = array( array( 'taxonomy' => 'category', 'include' => wp_get_post_categories($post_id, 'ids') ) ); } return $args; }January 21, 2020 at 2:29 pm #25369essenciadigital74
ParticipantHey, it is almost that but thank you a lot!
I just want to know if the function will run, because I put an exit() inside it and nothing changed.
-
This reply was modified 6 years, 4 months ago by
essenciadigital74.
January 27, 2020 at 12:48 pm #25510essenciadigital74
ParticipantHello!
How are you ?Do you have some answer about my previous question? I still cannot use the function, which worked 2 weeks ago…
Thank you.
January 28, 2020 at 10:21 am #25527Ernest Marcinko
KeymasterSorry, I must have missed your reply by accident.
Well, exit() is not going to change much, as this is within an ajax context, and you would have to investigate the XHR request body through the developer tools.
I checked the theme functions.php file via the theme editor, but I don’t see this code there (Generatepress theme directory), I think that is going to be the issue.
-
This reply was modified 6 years, 4 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.