If you were to localize admin-ajax.php then if you add these functions to functions.php:
add_action( 'wp_ajax_nopriv_create_posts', 'my_create_posts' );
add_action( 'wp_ajax_create_posts', 'my_create_posts' );
function my_create_posts(){
if (is_string($_POST['a'])) {
$name = $_POST['a'];
//echo $name; and soo on...
}
}
The ‘action’ in the ajax call is needed for defining to which ajax call to pair your function, defined in add_action.
Other thing is I don’t understand what are you doing with a, because $name is not used anywhere.
And if you want to check is a is being passed why not use isset($_POST['a'])
You would need to change in localize script the ajax url to:
'ajax_url' => admin_url( 'admin-ajax.php' )
Related Posts:
- How to make a image-size selected by default in Media upload – WP v3.5
- Apply class to every paragraph that holds image?
- Remove “Insert from URL” link in Media upload – WP 3.5
- static variable loop not working in WordPress
- How to change the wp-login.php page title?
- adding a filter to a shortcode?
- Hide custom image sizes from media library
- Set media upload attachment link to none and hide it in WP v3.5
- How to set custom cookies before output
- Permanently remove first image from posts
- Change the footer text on the login page
- How can I hook into and edit the text of a wp_nav_menu tag?
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- add_filter to post-gallery and remove all ‘s?
- Rename image uploads with width in filename
- How to make an meta_query optional?
- How to overwrite youtube embed?
- Rewriting search and pagination base
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Change comments form title on a page by page basis
- Filter the blog title displayed in the header
- Display only text to WordPress loop without loosing the text formatting
- Remove class that has been added by parent theme
- WordPress Ajax filter: Create two loops for different output styles?
- add_filter() inside another add_filter()
- How to filter specific element of an array in wordpress/php?
- How to disable sub menu items from being created?
- Trying to modify content.php
- Redirecting the lost password page request when using a custon login page
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- How to display custom seo title before the loop?
- How can i style “echo apply_filters”
- Adding body class to html tag that already has language attrubutes?
- Custom Bulk Actions handler not firing
- How to generate customized filtered output for the gallery
- Add class to all meta boxes for a custom post type
- Add a leading zero to pagination
- How to remove title tag with this filter
- str_replace not preserving whitespace
- Show content by using tags
- How to apply filter
- Update same content in multiple posts at once?
- Explode Content within specific HTML element
- Custom theme: adding unwanted tags in the content
- Apply filters when loading post via ajax
- Add end mark at the end of every article
- Add custom filter to register data in array
- Get terms of the posts with one query
- Create dynamic content from one WP page to multiple other pages
- Woocommerce Price Text
- Limit Taxonomy Parents
- Display a post based on its metabox selection
- Select All not working in a WordPress search filter
- Editing the contents of just one div on a page from wordpress
- Overwriting a Shortcode
- Custom field in title
- WordPress – show all posts + ones with specific tag
- Search box background on a different page template
- dynamically filter by category via sub-menu
- Display a list of users with avatar filterable with alphabets
- Loading a post’s content, into a div outside the loop, when it’s title is selected in a list
- WXR XML import is stripping php tags that I need to keep
- How can I add more code to this?
- How to add custom checkout field in user details mail template
- Keeping the previous get value and add another value when submitted
- How to refresh a template page on WordPress in 3 seconds – easiest method?
- Encode code snippet in AJAX endpoint
- Load files content [closed]
- AJAX: WordPress filters inside $html do not work as intended
- Why not showing all post by default in my jquery filter
- For each loop will not append to the_content hook
- Assign new post author IF another user in custom field on post transition
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Modify meta data before saving to database
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- How to change wp-admin and wp-login urls
- How to add different menu items on different menus?
- How to pass value to add_filter wpcf7_form_tag from another function?
- Custom Filtering date with newsletter
- Add text below WooCommerce short description if metabox value is true
- Is there a hook that I can use when a fatal error occurs?
- How rename wp-content and wp-admin folders correctly
- Unable to logout correctly after wp-login file was modified
- how to append ACF field data using one of the following filter/ hooks
- Changing upload directory temporarily
- Add an attribute on WP images attachment link
- Show post in elementor based on views and specific category with query id feature in elementor
- How to create advanced custom fields for backend content
- Display featured posts first, then display all others within a specific category in WordPress
- Edit password change email text or disable it
- Adding Author Filter to CPTs
- How can I display formatted content using the_content filter?
- Using send_password_email filter after wp_update_user
- Replace all instances of string in page (including header and footer)
- Prevent publishing of uncategorized posts
- WordPress query_posts with multiple tax_query
- Ajax Filters with Multiple tax_query args
- How do I ensure that the URL parameters are updated correctly when multiple filters are applied
- Filtered queries not responeding to page path