First of all. You’ll need to follow the ajax best practices in WordPress. That means, add the right actions for your functions and call them also with the admin ajax url.
So your jQuery ajax should call the admin_url, and you’ll need to send along an ‘action’ data in this example, the name of the action: ‘subscribe’; (wp_ajax_subscribe minus the wp_ajax_ ). You can include that with a hidden input field called with name ‘action’ and value ‘subscribe’, so you serialize function picks it up from the submit event.
url: '<?php echo admin_url( 'admin-ajax.php' )?>',
add_action( 'wp_ajax_subscribe', 'ja_ajax_subscribe' );
add_action( 'wp_ajax_nopriv_subscribe', 'ja_ajax_subscribe' );
function ja_ajax_subscribe(){
$result="some data";
wp_send_json_success($result);
}
Related Posts:
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- AJAX load more for different custom post type loops
- WordPress notification if new post published
- Submit Custom Postypes from frontend
- How to submit the date with ajax?
- Show ajax form resuslts in page
- Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()
- Get current post type within functions.php
- Getting the URL of the parent page
- wp_insert_post generates endless posts
- Remove standard meta boxes from custom taxonomy
- Ajax posts filter by date, comments, top views, top likes
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Ajax Check Post Status
- What’s the difference between same wp functions get_posts(); functions in different form?
- Ajax not working properly
- I did group my search results by post type, but how can i give each of them its own order?
- Dequeue scripts and styles only for specific custom post type
- Function to display custom post type on front page makes menu items dissapear
- custom post type not showing in menu
- Received nothing after executing AJAX post function
- Show category ID on custom post type
- Filtering WP_Query Dynamically on the Front-End
- How to retain $_POST data when submitting form to custom page
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Storing posts from query and accessing later via AJAX call
- How to customize a permalink (URL) structure?
- Loading custom content type from ajax results?
- Custom Post Type with Templates using Meta Boxes?
- Display users uploaded files as posts
- Can I list a custom post type within another custom post type in the admin area?
- Change custom post type slug from plugin options
- Post form as custom post
- Can’t edit custom post type
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Set URL link to featured image of custom post type
- How to store data from multiple forms using ajax and php
- Change CPT archive title
- PHP variable not regenerating when publishing multiple posts at the same time
- On update or create post redirect to current post position in list
- Ajax Custom Post Filter is not filtering
- I need to add endpoint for wordpress categories
- How to target a specific custom post type post and its all children and grandchildren?
- Featured image overlay when changing post status
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- get_post_meta not working on publishing
- JS innerhtml changing style when using AJAX
- Redirect 404 page with ID in slug to associated page with same ID in slug
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Display featured image from one CPT within another CPT query
- Query taxonomy of taxonomy of custom post type
- Best way to style first post differently?
- How to make custom posts types display when published for the future
- How to rewrite url for any specific taxonomy?
- create a new page from a custom post type similar to an authors page
- CPT archive admin menu label
- Anon function and add_meta_box
- Custom post type – use ajax to display sub pages
- Form action/link to render a plugin in WordPress front-end
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Hide a widget inside a div on specific type of post
- Shortcode not working with post counter
- Changing default ‘posts’ parameters with register_post_type_args
- Load Custom_post_type categories post with ajax
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Dynamic Custom Fields
- A form that can save/edit after first input
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Cannot save CPT meta box
- Allow users to create posts without logging in?
- How to change permalink to include custom post type
- How to make front end form only accept certain values
- Edit Custom Post Type on Custom Admin Page instead Post Admin
- Using POST method in meta box, no results
- Load Next Posts With AJAX not working with custom post type
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- Add term to custom post type on draft
- Form action doesn’t work if slug isn’t same as custom post title
- How to assign classes to all elements?
- next_/previous_post_link() `in_same_category` appears to fail when true
- Want to be able to sign up subscribers as authors
- Load scripts based on post type
- Different Category system needed for the Custom Post Type
- Retrieve custom post types by custom taxonomies with WP_Query
- Global custom meta box
- Template not working for the custom Post type
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- $post not working working in AJAX plugin with custom post type
- categories should be available across all custom post types
- Warning: Invalid argument supplied for foreach() in post.php [closed]
- Featured Image field not appearing in Custom post type
- Post-thumbnail only for specific post-types?
- custom post type metaboxes not saving
- Load Next WordPress Posts With AJAX?
- Custom Post Type & Custom Menu Walker to append custom class for active post types