Solution was simple. Set DOM element value in JS variable instead of “document.getElementById(‘post_category’).value” in array.
var submitBtn = document.getElementById('submit-post-btn');
submitBtn.addEventListener('click', function(){
var categoryTerm = document.getElementById('post_category').value;
var postData = {
"title": document.getElementById('post_title').value,
"content": document.getElementById('post_content').value,
"status": 'publish',
"categories": [categoryTerm]
}
};
Related Posts:
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- How do I query posts by a sub value with the API?
- How to submit a button automatically after every scheduled hours?
- JavaScript implementation of Gzip
- Using Backbone with the WordPress AJAX API
- WP-AJAX vs WP REST API: What to use for requests to the website from outside?
- Including WordPress in RESTful API
- REST API endpoint for elasticpress autosuggest
- How to properly use wp.ajax.post?
- Gutenberg – how to correctly perform ajax request on backend
- Refused to execute script from ‘***’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled
- AJAX request from Chrome Extension to WordPress Website
- Dynamically changing navigation links (next and previous) via AJAX
- Quick Edit: Selected Custom Taxonomy Not Refreshing After Save
- Vue.js + AJAX Shortcode
- Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)
- WP REST API route request explain
- fetching via fetch/ajax gutenberg block data from third party
- Confused on AJAX submit form through page template
- ajax and nonce when JavaScript is in a seperate file
- admin-ajax.php HTTP400: BAD REQUEST – The request could not be processed by the server due to invalid syntax
- Solve cors problem using rest api or ajax
- AJAX issue – Uncaught SyntaxError when processing Zip File
- WordPress AJAX Call Not Return Result
- Is there a hook to process a backbone restful PUT request inside wordpress?
- Nonces, AJAX, script variables & security in WordPress
- How to localized one js file for different actions?
- wp-admin AJAX with Fetch API is done without user
- Admin Ajax and HTML5 Formdata
- Call javascript function when category was added via ajax
- Populating content dynamically via AJAX and Advanced Custom Fields [closed]
- Help with AJAX front end comment moderation
- How to add WP API and JS featured image attachment
- Woocommerce Ajax Add cart not working
- how to send Ajax request in wordpress backend
- Identical wp_rest nonce returned from rest_api
- Ajax Modal Flickers When Opened Multiple Times
- Load JavaScript from a post that’s loading into Fancybox via ajax
- splitting the URL using jQuery
- How do I get reusable blocks via frontend REST API?
- Is there builtin way to use protected AJAX endpoint?
- AJAX Load more on CPT returning random posts
- rest_no_route custom route
- Test WordPress api with postman
- Refresh Markercluster after ajax call
- How to load content from many posts on a page, only if needed
- Making an ajax request from a different domain
- Performance optimization of tree like structure
- Radio buttons live refresh in the customizer
- Gravity Forms closes my popup on Validation Error [closed]
- Why is wp_localize_script returning false?
- merge wp rest api query to get posts per category does not work
- Ways to load admin-ajax faster without initializing all plugins?
- Using admin-ajax prevents regular php form submission
- How to make a fetch() POST request to wordpress rest api?
- post values to custom post type which has advanced custom fields
- wp_mail doesn’t work when logged in?
- Hide Load more Ajax button if there is no more users to load or less than the number?
- How to disable drag-and-drop upload function in Media Library?
- javascript ajax and nonce
- Is there a better way to access transients using javascript
- Run javascript upon successfully set featured image
- admin-ajax.php (aborted) error when using jQuery.get
- Replace link with form to pass variables to javascript / ajax
- Ajax page load without reload
- Load page HTML content through AJAX
- How to display contact form 7 form in vanilla js without jquery in frontend
- Get localize of a loaded javascript
- Updating failed. The response is not a valid JSON response. specific to my browser when I include javascript in my html
- Uncaught TypeError: Cannot read properties of undefined (reading ‘message’) [closed]
- REST public POST giving 403 forbidden nginx
- Refresh Gutenberg with JS for it show updated post
- javascript onClick update user_meta from jquery.ajax
- how to make sure js is enabled before executing php function
- How to Object.freeze wp_localize_script
- How to pass value from ajax to php in no conflict mode?
- ERROR while passing data from JS to PHP via AJAX
- Ajax sometimes work and sometimes just don’t work
- 404 error custom post type rest api
- React to AJAX adding to the page
- Download doccument on server rather than clients browser
- Using existing ajax data that is loaded into page
- How to require files in a custom endpoint
- Javascript output now showing in custom widget
- Ajax call from Plugin using Class
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Ajax call on class returns old data
- How to safely pass post_id and user_id via AJAX to the backend (prevent user from changing it via JS)?
- Ajax show custom post data form & script
- AJAX form not working, still reloads on submit
- Get post details with pure javascript ajax
- Jquery wrap permalink in a data-attribute?
- How to trigger lost password email using REST API?
- ‘Dehighlighting’ navigation once clicked
- AJAX admin Internal 500 error Failed to Upload
- Using Javascript Callback from plugin in a theme
- how reduce fetch/XHR response time
- Custom WP rest api endpoint only working on non https?
- Escaping admin_url output being passed to js (esc_js vs esc_url)
- Why are the most recent posts not appearing in a fetch request, unless I’m logged in?