You’re almost there. Here’s the part that is setting the author of post to user with ID = 1:
'post_author' => 1,
'post_status' => 'publish',
'post_type' => 'testimonial',
'author' => $current_user->ID,
You even try to set the author to $current_user, but you don’t initiate this variable anywhere in your code and you set author
field instead of post_author
.
So here’s the correct version:
'post_author' => get_current_user_id(),
'post_status' => 'publish',
'post_type' => 'testimonial',
Related Posts:
- Get Author Post on author.php with AJAX
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- How to check if I am in admin-ajax.php?
- Ajax in a settings page (update_option is undefined)
- gettext does not translate when called in ajax
- Execute one AJAX request after another AJAX request finished
- admin-ajax.php vs Custom Page Template for Ajax Requests
- Load tinyMCE / wp_editor() via AJAX [duplicate]
- Is there a hook that fires before an ajax call?
- AJAX request from Chrome Extension to WordPress Website
- How to correctly load wordpress in a non WP script for AJAX request
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Why is admin ajax reloading my page
- Plupload in metabox – AJAX action not working in Class
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- CPU usage: AJAX and Heartbeat API on admin pages
- Ajax call in wordpress not working for subscriber user in front site
- Solve cors problem using rest api or ajax
- Can part of my WordPress website be headless?
- Nonces, AJAX, script variables & security in WordPress
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- Why does WordPress Heartbeat login not refresh the nonces?
- Why would admin-ajax.php redirect to the home page for logged out users?
- wp_localize_script escaping my url – fix or alternative
- Admin Ajax and HTML5 Formdata
- Implementing an AJAX POST API call in wordpress
- Placement of add_action() for ajax callback?
- WordPress ajax problem need wordpress expert?
- Identical wp_rest nonce returned from rest_api
- Ajax WordPress Login needs to be stayed in current page Url without redirecting
- wp_ajax function did not call
- wp_handle_upload returns empty error array
- Loading comments in ajax – comment-reply function missing $args
- Woocommerce update product price via AJAX
- How do I query posts by a sub value with the API?
- Popup or admin/update notice on post/page edit screen without page refresh
- Enqueue script in plugin is not working
- Single page site + pushState?
- Interim-Login form on frontend
- Ajax call does not work for this simple code
- WordPress ajax call returns a zero though die()
- Save value from Javascript object to WP user
- wp_update_post onclick button using ajax
- Ajax insert or update data
- Check ajax triggered from front-end or from dashboard
- Localize script not working
- Add Ajax to rating button
- Why, if a function accepts arguments, it fails on ajax calls?
- wp_ajax declaration confusing for Front end
- How to disable drag-and-drop upload function in Media Library?
- WP_query offset seems to be counting draft post – AJAX load more
- Can’t retrieve any content from Ajax-loaded page
- adding ajax load more to display images from meta box
- Can’t load search results with ajax
- wp_ajax is not calling the action
- Deny dashboard access breaks ajax requests
- Run javascript upon successfully set featured image
- update_option in WordPress AJAX
- ajax in admin menu
- How to load dynamic option with ajax
- How do you use do_shortcode via AJAX call?
- Auto-suggest to display meta-data, but not to include it upon click
- Register Template
- Ajax Favorite from foreach (how to specify which result result is processed)
- change wordpress pagination url after doing the request
- WordPress responds to the ajax request with readyState 1, 2, 3 before responding with 4
- Filter images from media library by guid meta field
- Counting Posts with multiple taxonomy and terms condition using MySQL and AJAX
- Refresh Gutenberg with JS for it show updated post
- How to Object.freeze wp_localize_script
- WordPress New Post via ajax call
- 400 Bad Request getting on AJAX Call
- admin-ajax.php 403 errors – no caching, permissions are fine
- gform_after_submission does not work on ajax enabled form
- How to add Ajax to this Pagination i made?
- Adding user using admin ajax by a user with custom role
- How can I run two AJAX requests simultaneously in WordPress?
- Following/Followers Users list Using Ajax Pagination inside Author Profile
- Change button text after ajax db update
- How to implement AJAX within a class storing shortcode atts as class variables
- Jquery wrap permalink in a data-attribute?
- (Frontend AJAX) get post data WITH image thumbnail?
- Load .php file into div using ajax
- Native WordPress Video Shortcode Not Working After Post is Loaded via Ajax
- AJAX Post from same domain to a wordpress page
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Using AJAX for dynamic settings pages
- Speeding up admin-ajax.php
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- AJAX admin Internal 500 error Failed to Upload
- Class property not visible inside ajax callback function?
- $wpdb Ajax not redirecting to main page
- how reduce fetch/XHR response time
- wordpress ajax bad request 400
- Custom WP rest api endpoint only working on non https?