get_the_content()
must be used inside the loop, or otherwise you’ll need to use setup_postdata();
providing the post object.
Try the following:
function ajax_action_stuff() {
$post_id = $_POST['post_id'];
//Query the post and set-up data
$post = get_post($post_id);
setup_postdata( $post );
update_post_meta($post_id, 'post_key', 'meta_value');
//Return response as an array. This will give us data.title and data.content browser-side.
$response = array()
$response['title'] = get_the_title();
$response['content'] = get_the_content();
echo json_encode($response);
exit;
}
This has not been tested
Related Posts:
- AJAX handler throws 400 (Bad request) – why?
- ajax live search for post title
- Display a function using AJAX
- Ajaxing function in widget class
- woocommerce target button with class after ajax update
- WP Ajax Function Always Returning undefined
- Scripts not appending to element in AJAX call – why?
- How to search using ajax for exact phrase or words in an input field?
- echo custom fields with AJAX
- Are innerHTML elements visible to jQuery functions?
- get content from page through AJAX
- Get URLs for AJAX Filter Checkboxes WordPress
- Populate Product Regular Price with a calculated ACF Field Value
- Ajax Form Issues using Lightsail (AWS)
- post value to function with Ajax and jQuery
- How to use `foreach()` in ajax call
- Multiple Notifications SetInterval
- WordPress Ajaxifying not working properly
- Load scripts into an AJAX div
- Load scripts into an AJAX div
- Automatic add space if user enters number(any digit)
- Ajax call does not work for this custom code
- AJAX values converted to PHP Variables?
- iOS and ajaxComplete
- In jquery use php variable to execute an enqueued jquery file
- Tags break custom Excerpt function
- Run a jquery script on on a certain template page
- Add php code to wp_print_scripts?
- How can i unload effect.min.js file?
- PHP 7.1 | Warning: A non-numeric value encountered in
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Loading two different AJAX requests on two different pages
- WordPress notification if new post published
- Why i can’t get custom fields value or post ID via Ajax?
- Check if a value exists in database table
- Where is this JQuery coming from?
- processing form data with ajax
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- How to load jQuery in TOP of wp_footer?
- Passing Jquery value to WordPress function
- Email Exists ERROR into Ajax registration form
- WordPress can’t get jquery/unslider to work
- Add loggedout class on body using a function or JS
- How to use get_posts() function in functions.php
- Include Jquery libraries in wordpress theme?
- Ajax resetting my global variable
- contact form in template with jquery,validate and ajax
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- Execute Jquery when a specific page in my plugin is loading
- Creating multiple category drop down
- How to setup a popup registeration page in wordpress with function.php
- colorbox not loading in
- How to add php within jquery
- Using jQuery .after inside loop
- Help with IF has focus then… statment
- the_excerpt function not showing image
- Message notification for user
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Database entry removed on browser refresh, Ajax PHP jQuery
- Detect Ajax call inside pre_get_posts function
- wp_set_object_term via js btn frontend
- Ajax filter with loadmore button
- Hide ‘add to cart’ when certain value in dropdown is selected
- Cannot pass value variable to WP AJAX functions
- What is the earliest Hook a Script can use?
- WordPress does not load jQuery
- price of product can’t return when get data of product in functions.php
- WP AJAX Request Not Working
- Update $wpdb query with AJAX
- Ajax in plugin fails – but only on one blog – no idea why
- WordPress Ajax not returning Response
- Finding post ID dynamically on click
- Images with overlay
- Using AJAX on frontend: Synchronous XMLHttpRequest deprecation except for admin role
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- How to call a function from functions.php with ajax?
- i can’t use wordpress functions in ajax loaded php file
- Function stops working
- wp_ajax add_action fuction won’t fire on custom jQuery action
- admin-ajax.php 403 forbidden only when calling from external file
- How do i create a search option for pdf’s only
- Execute jQuery with custom event listener after successfully add an item to the cart
- What is best practices to move the following code into a function?
- Find the method which AJAX GET calls
- How to create admin ajax function for my contact form
- admin-ajax.php & my wp-admin folder url showing in header
- True parameter but jquery register in header and not in the footer with wp_register_script
- wordpress function through ajax not being called
- same get_posts function works diffrently in tag.php and functions.php
- wordpress ajax is not working for dropdown selection
- WordPress Jquery+scripts enqueue issue
- Regex works in regexr, but not if I filter content [closed]
- Moving CDN jQuery to footer does not work?
- Adding a jQuery rotator function
- functions.php filters not applied in AJAX call
- Pass max posts to Javascript
- Updating site content after an AJAX call without a page reload
- Problem in outputting shortcode
- Problem in shortcode outputting content