results page override functionality on other pages

Home Forums Product Support Forums Ajax Search Pro for WordPress Support results page override functionality on other pages

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 month, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #38843
    martinclement
    martinclement
    Participant

    Hi

    I have a question regarding: https://documentation.ajaxsearchpro.com/behavior/results-page-override

    How can I make sure, that it overrides not only on the search results page, but also on other pages. Because I have a searchfield and searchresults module on my homepage. ASP seems only to affect the search page template. Is it possible to add a certain code to my page, to “trick” your plugin into thinking my homepage is the searchpage?

    I had contact with Ernest Marcinko, who told me to open a ticket here.

    Thank you in advance for your help! Love your plugin by the way!

    Best regards
    Martin

    #38858
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Martin,

    In theory it might be possible. There is a non-documented hook called asp_query_is_search, which is executed right before the plugin executes the override. If the hook returns a boolean true, the it will override.

    Using a custom code like this:

    add_filter('asp_query_is_search', 'asp_force_override_on_conditions', 9999, 2);
    function asp_force_override_on_conditions($is_search, $wp_query) {
    	return true;
    }

    ..will enable override in all query cases. However, that is probably not what you want, you may want to check certain conditions of your own. The search override hook is applied on the posts_results and posts_request wordpress core hooks.

    Best,
    Ernest Marcinko

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


    #38861
    martinclement
    martinclement
    Participant

    Thanks for your fast response!

    So if I understand it correctly, by adding $is_front_page, the override should apply on the static front page that I added. It seems to work, but the issue I have now is, that it always shows the first article from the posts list, instead of the front page.

    My code:

    add_filter('asp_query_is_search', 'asp_force_override_on_conditions', 9999, 2);
    function asp_force_override_on_conditions($is_front_page) {
    	return true;
    }

    Any chance you can help me? Thank you very much for your time.

    #38862
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    No, your code is incorrect. The first argument of the function will always be a boolean value returned by the plugin – the result of the search query check. When the function in the code returns true the override applies, when false, it does not. All you did was rename the $is_search variable to $is_front_page, it will make no difference whatsoever.
    You can check the wordpress hooks documentation to understand how they work. Within this hook you will probably have to use the $wp_query argument, to check what query is executed, to determine the outcome of the function.

    Best,
    Ernest Marcinko

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


    #38869
    martinclement
    martinclement
    Participant

    Thanks again for your help. I found another easier solution using the elmentor-specific solution from the settings. Spent way too much time… I just had to add the class to my element and it worked.

    You truly made an awesome plugin! 🙂

    Best regards
    Martin

    #38882
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.