I got everything working but it may not be the most elegant of solutions.
I put the form text as well as the empty results div on a page. I created a small plugin that checks to see if we are on that page. If so, insert the JavaScript into the footer. Otherwise, do nothing.
This checks for the page we are on:
public function display_group_information($content)
{
global $post;
if ($post->post_name == 'groups-activities-and-events'){
add_action('wp_footer', [$this, 'load_group_ajax']);
}
return $content;
}
This adds the required javascript:
public function load_group_ajax(){
?>
<script>
!function(r){function n(n).....("#grpSearch").submit(n)}(jQuery);
</script>
<?php
}
Again, probably not the most elegant way of doing it but it works.
Related Posts:
- Allow only new sub-pages to be created
- Add a new page to wordpress programmatically
- AJAX request from Chrome Extension to WordPress Website
- What’s the most minimal way in which a page can be hooked into WP?
- Call the content of a page in AJAX in WordPress
- How to add WP API and JS featured image attachment
- How get get list of pages in ajax search
- Can’t get done anything with admin.php response
- Loading Multiple Comments Pages via Ajax?
- Is it possible to create new user from external form using REST API?
- How To Render Shortcode In AJAX Response?
- Create multiple pages with tables from json file
- register_rest_field only for specific page
- My AJAX requests take 30 seconds to complete
- List of pages – AJAX load more
- How to submit a button automatically after every scheduled hours?
- Dynamic activation page in WordPress
- Post current post type to my Ajax
- Create a PAGE using wordpress API using the PAGE template and change specific content
- How to use a common header and footer in the ‘Custom HTML’ block across pages in WordPress?
- Add infinite scroll to content splitted post
- Check if wp-login is current page
- How to get current page ID outside the loop?
- Contact Form on WordPress Sites?
- Page returns 404 with POST variables, but not without
- Custom templates not showing up in template dropdown
- Get page id by template
- WordPress Rest API custom endpoint optional param
- Using pre_get_posts on true pages and static front pages
- Get the content of a specific page (by ID)
- Using the Rewrite API to Construct a RESTful URL
- How to get page title with the page ID?
- Show more than 20 items in pages or posts edit dashboard
- Allowing user to edit only certain pages
- How to display last 3 posts (recent posts) in a static page?
- How to give paged links custom title?
- How to set post slug when using wp_insert_post();?
- How can I keep the content of my pages version controlled?
- How to load javascript on custom page template?
- How to configure WordPress to handle 75,000 pages?
- How to update page status from publish to draft and draft to publish
- Check if is on child-page of a particular page
- Change page template programmatically ?
- Conditional tag to check if ‘page.php’ is being used?
- Customizing the URLs of WordPress Login and Sign-up Pages?
- How to disable posts and use pages only
- featured image as background image on pages
- Check IF is a “single product page” and Check the “role” for a Redirect
- A check for if is parent page, if has children, if has grandchildren
- Query WP REST API v2 by multiple meta keys
- How to load JS and CSS only on specific Pages using is_page()?
- Listing pages which uses specific template [duplicate]
- Proper way to get page content
- Access the same page from multiple urls (wildcard)
- Is there a JavaScript API? How to access public and private data in JS?
- Create a page without adding a page in the Database
- Is there a way to change the default page template selection?
- Can I have two child pages of different parents with the same name?
- What methods to use to create small, editable pieces of text for static pages?
- Using Backbone with the WordPress AJAX API
- How do I cache (core) API requests?
- Show Default Editor on Blog Page ( Administration Panel )
- Hide page visual editor if certain template is selected?
- WP REST API only returning partial list of users
- What is the difference between $paged and $page?
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
- multi page password protection
- Create a “Dummy” parent page for a hierarchy in page listing?
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- How do I convert a page’s title to lower case?
- Get top level page parent title
- How to add a specific widget to only 1 page?
- WP-AJAX vs WP REST API: What to use for requests to the website from outside?
- Restrict admin access to certain pages for certain users
- page title, parent tilte and grand parent title
- How to add jQuery script to an individual page?
- Slow REST API calls on self-hosted WordPress [closed]
- WordPress page edit does not save selected template
- Add a Page without header and menus?
- What is an alternative to get_page_by_title()?
- Password protect page with multiple passwords
- Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?
- Create pages automatically if they don’t exist
- Find empty pages or pages which have less than x characters
- Set page template automatically based on parent
- Editing Complex Pages in Visual Mode
- When adding a custom REST endpoint, where do you put the endpoint function, and where do you put the function registration call?
- Retrieving pages with multiple tags using REST API
- Including WordPress in RESTful API
- Link section within page with slash (/) and not hash (#) without reloading the page
- Creating a template using a specific slug name, for a page with a parent page
- Can I display submenus in groups, using wp_list_pages?
- Is there a default template file for child pages / subpages?
- Get wp_get_attachment_url outside of loop
- Order by menu_order and title?
- REST API endpoint for elasticpress autosuggest
- Require title for pages
- WP Page and Subdirectory with same name
- Replace Dashes Before Title in Page List