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
- Remove “Insert from URL” link in Media upload – WP 3.5
- How to change the wp-login.php page title?
- Hide custom image sizes from media library
- add_filter to post-gallery and remove all ‘s?
- How to overwrite youtube embed?
- Filter the blog title displayed in the header
- How to change featured content to a different tag in WordPress Twenty Fourteen?
- body_class filter – Is there a better way to write this code?
- How To Change The Html of Products filtration sidebar in Woocommerce?
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- Filter get_the_title to remove certain characters?
- Wrap First Character after in a tag
- Get posts with at least one category in common with current post?
- Set post title based on first h2 element in the content section
- Change the site tagline (or similar) based on current page
- WooCommerce Related Products by Attribute
- Custom filter in admin edit custom post type responding with invalid post type?
- add_action shortcut?
- Edit incorrect password message WordPress
- Error when adding excerpt to the content through functions.php
- Add data attribute to each li in menu
- Ajax category filtering products default show all
- Add a specific part of current category page url to shortcode
- Dynamic content based on a URL parameter
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Remove the first 5 characters of the_title and orderby that
- Print last modified date only on posts
- How to add an arrow to menu items has submenus
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Unique icons next to each WordPress menu item
- Change tinyMCE editor to allow marked content when pasting from Word
- Alter required message using comment form api
- How to edit php code in WordPress Post file?
- Change page title from page using php via php executed from page/post itself
- Override a function defined in wp-includes/comment-template.php
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Content filter won’t work
- Warning: in_array() null given in PHP function
- Upload multiple files in randomly generated folder using wp_upload_bits
- Create page template via functions.php?
- How to have different site identity logos on each page on Astra Theme [closed]
- How do I create a secondary version of the_content
- Get the_content surrounded by instead of
- Displaying content on posts page based on category
- Display an image based on field value
- Can I remove or edit an include() from a function with a filter?
- Dynamically adding filters
- WordPress Twenty Eleven PhP – forcing php code to skip first post on homepage?
- How can I call a specific file (via php) by referencing the logged-in username?
- WordPress doesn’t load HTML
- search and add in wordpress content
- apply_filters with several different values?
- How can I modify this code to make the search box include tags and meta
- For some time, some of my pages do not display the content anymore. Any idea where this could be coming from?
- How to add a custom filter (by coding) before access one wordpress page ? And where to call the custom filter?
- How to sort WooCommerce products page by latest in-stock items first?
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- Show related products by attribute based and certain conditions
- How to Create custom block for displaying information in content section which act like shortcode
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Filter ‘comment_notification_text’ not working
- How to run php code only for a specific widget on a page and not all widgets on that page?
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Change the “Show All” button in a WordPress Portfolio Filter
- Change lost password url to a mailto URL in WordPress
- Shortcodes not processing inside post content
- Remove span tags from WooCommerce Downloads page
- Add a top bar to a wordpress theme without editing the header.php file?
- I want to hide “sold by” on certain pages with id page 43
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- using filter and hook inside class
- How to bind each “the_content” elements to a custom variables
- Filter portforlio with librairie isotop
- add_filter() inside another add_filter()
- Redirecting the lost password page request when using a custon login page
- Custom Bulk Actions handler not firing
- How to generate customized filtered output for the gallery
- Add a leading zero to pagination
- How to apply filter
- Add end mark at the end of every article
- 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
- 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
- Encode code snippet in AJAX endpoint
- AJAX: WordPress filters inside $html do not work as intended
- Why not showing all post by default in my jquery filter
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- How to add different menu items on different menus?
- How to pass value to add_filter wpcf7_form_tag from another function?
- Add text below WooCommerce short description if metabox value is true
- How rename wp-content and wp-admin folders correctly
- Unable to logout correctly after wp-login file was modified
- Show post in elementor based on views and specific category with query id feature in elementor
- Prevent publishing of uncategorized posts