asp_query_args IS NOT WORKING

Home Forums Product Support Forums Ajax Search Pro for WordPress Support asp_query_args IS NOT WORKING

This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #25363
    essenciadigital74
    essenciadigital74
    Participant

    Hi!
    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!

    #25364
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    There was no change whatsoever regarding that hook. Can you please paste the function with the hook here? I would like to validate it.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25365
    essenciadigital74
    essenciadigital74
    Participant
    add_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);
    }
    #25368
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25369
    essenciadigital74
    essenciadigital74
    Participant

    Hey, 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.

    #25510
    essenciadigital74
    essenciadigital74
    Participant

    Hello!
    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.

    #25527
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Sorry, 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.