Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › results page override functionality on other pages
- This topic has 5 replies, 2 voices, and was last updated 3 years, 9 months ago by
Ernest Marcinko.
-
AuthorPosts
-
August 13, 2022 at 7:35 am #38843
martinclement
ParticipantHi
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
MartinAugust 13, 2022 at 2:19 pm #38858Ernest Marcinko
KeymasterHi 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.
August 14, 2022 at 8:56 am #38861martinclement
ParticipantThanks 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.
August 14, 2022 at 9:53 am #38862Ernest Marcinko
KeymasterNo, 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.August 14, 2022 at 1:52 pm #38869martinclement
ParticipantThanks 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
MartinAugust 16, 2022 at 9:49 am #38882Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.