Requesting some information for plugin template modification

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Requesting some information for plugin template modification

This topic contains 5 replies, has 2 voices, and was last updated by Tuhin Bhuiyan Tuhin Bhuiyan 6 years ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #9175
    Tuhin Bhuiyan
    Tuhin Bhuiyan
    Participant

    Hi,

    First, I want to thank you very much for making this plugin. 🙂 never knew this plugin could come in handy.

    I am trying to modify search results URL by adding custom value at search results URL. I have followed one of your guide.
    I added multiple search shortcode in different pages, But as I need this modification it to be conditionally working for specific this page only: https://tmb.tuhinbhuiyan.com/write-review/ , but It is not working. This is the code snippet I added in functions.php

    add_filter( 'asp_results', 'asp_custom_link_results', 1, 1 );
    function asp_custom_link_results( $results ) {
     if (is_page(985)) {
      // Parse through each result item
      foreach ($results as $k=>$v) {
         // In this context the
         //     $results[$k]->link
         // variable holds the result link. Make modifications to that variable.
        $results[$k]->link  =  $results[$k]->link . '?review';
      }
      return $results;
     }
    }

    Can you please suggest me what I am doing wrong in there?. Why it is not working for the specific page.
    I am really unable to use conditional “if statement”, Even tried to modify the template vertical.php using if statement it but it is not working there at all. Whenever any keywords get inserted , it shows as No Result. modified vertical.php file attached. It took me a hard approach as I am wanting to show some custom data from Listify theme (which using wp job manager) at vertical.php template like total reviews and priority product listing by based on rating. eg: https://tmb.tuhinbhuiyan.com/listing-category/accessories/ , keyword: baby. Trying to replicate this type of search item. : http://take.ms/w75sf

    Also, I am working on a child theme and as per your guide I moved this template files into child theme folder but search plugin is not getting them from child theme folder instead it is using the plugin dir for loading those template. If I move them to parent theme then it works. Can you possibly tell me why template files are not working in child theme?. and how I can make it work?. So, my change’s doesn’t get override after a theme update.

    I just updated the plugin and it is using scroll to showing overflow content. How do I disable it so it shows without overflow and no scroll, but with More load button?.

    I will really appreciate if you can answer me please with as much example as you can provide along 🙂

    Thank you a lot,

    Attachments:
    You must be logged in to view attached files.
    #9187
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    I will try to explain everything I can in details. While customizations are not part of the support, I gladly help, but please note that for this reason I cannot take responsibility if some of these suggestions won’t work.

    There are two (possible) issues I can see with the code there, one is a minor issue, the second one is bigger.

    The minor (possible) problem is that the return statement is within the conditional statement. I’m not sure if that is intended, but if the

    return $results;

    is not executed, then no results are returned if the conditional statement fails. If that is intended, then I suggest changing that to:

    if ( something ) {
        // Do your stuff here as before
        return $results;
    } else {
        return array();
    }

    Because the handler expects an array of results, even if it’s empty.

    The second problem is that is_page(985) is always going to return false. This code is exectued in an ajax context, which is a separate process from the page view – so there is no information in that process of the currently viewed page, where the request is sourcing from. So calls like is_page(), is_home(), is_single() etc.. are not going to work, because this is not a pageview, it’s an ajax request.

    There are two ways developers deal with this situation:
    1. To send the page ID along with the ajax request, and check that variable within that code. This however requires to change the plugin code directly, which is not what we are aiming for.
    2. Using a different method with the given variables at the time of the ajax request.

    Right now the best bet is to try to identify the search instance differently. If you take a look at the ajax response via console, you can see the variables passed on to the ajax handler, which are also accessible in that particular code snippet!
    As an example, I did a search on the demo: https://i.imgur.com/KcpYP3H.png

    As you can see variables passed on to the handler are:

    
    $_POST['action']
    $_POST['aspp']
    $_POST['asid']
    $_POST['asp_inst_id']
    $_POST['options']
    

    The one that is interesting for us is $_POST[‘asid’], which contains the instance number of the search, that started the ajax request.

    If page 985 has a different search instance as the other pages, makes it possible to distinguish from others. I would use this snippet as a sample:

    Don’t forget to change the 1234 to the search instance number you are using.

    ————————–

    Disabling scrolling: On the Theme Options -> Vertical results panel change the viewport option to a very high number, like 100 or so: https://i.imgur.com/qHwGryv.png

    ————————–

    Child theme: I just checked, it’s indeed not returning the correct directory when using a child theme, I will have to look into that.
    For a possible temporary fix, open up wp-content\plugins\ajax-search-pro\includes\classes\etc\class-asp_helpers.php file and scroll to line 145, which should be:

    $theme_path = get_template_directory() . "/asp/";

    and change that to:

    $theme_path = get_stylesheet_directory() . "/asp/";

    If that works, then use it, I’m definitely going to fix this in the upcoming release, so you should not worry about loosing this change.

    Best,
    Ernest Marcinko

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


    #9230
    Tuhin Bhuiyan
    Tuhin Bhuiyan
    Participant
    You cannot access this content.
    #9299
    Tuhin Bhuiyan
    Tuhin Bhuiyan
    Participant

    Another question. How do I possibly show auto populated results only from selected category?.

    I am trying to use Advanced Options > Exclude Results > Exclude posts (or cpt) by taxonomy terms
    But when I drag all other taxonomy terms to exclude list and keep only one in the available list. And saving them is not saving the data. Also at DEMO it is not working either. What I get is “No Results” but I have posts assigned within that taxonomy terms.

    Possible setup issue or plugin bug, Any idea please?. Also, would like to receive a reply for previous questions.

    thanks.

    #9326
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    First, to target multiple IDs you can indeed use an array, like so:

    if ( isset($_POST['asid']) && in_array($_POST['asid'], array(3, 4, 5, 6)) ) {

    On results pages these filters won’t work, these are only invoked when using the ajax search.

    To add content to the results page, you will probably have to use the the_content filter to attach the handler, but it depends on your theme as well. Some themes do not execute this filter on archive/search pages.

    An example use of the_content filter, targeting only search archive page:

    This one I’m not sure if works, but I think the search ID is passed on to the results page as well:

    The taxonomy-term exclusion seems to be a bug indeed, I’m surprised nobody noticed it before. I will look into that. A new release is coming out today, I will try to fix this issue as well with that.

    Best,
    Ernest Marcinko

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


    #9333
    Tuhin Bhuiyan
    Tuhin Bhuiyan
    Participant

    Thank you for your valuable response. I will play around with this suggestions and see how these goes.

    Also, I look forward to new release and hopefully it will be included with plugin path fix for child theme to overriding ajax search pro templates.

    Cheers! 🙂

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

You must be logged in to reply to this topic.