Unable to get_the_content(); of a post in WordPress via AJAX

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. … Read more

Redirect users away from Admin breaks ajax

You can and a check for the DOING_AJAX constant which is defined on an Ajax in your conditional check: function no_admin_access() { if ( // Don’t do this for AJAX calls ! defined( ‘DOING_AJAX’ ) // Capability check && ! current_user_can( ‘delete_posts’ ) ) { // Redirect to home/front page wp_redirect( site_url( “https://wordpress.stackexchange.com/” ) ); … Read more

Conditional Ajax inclusion

When you call admin-ajax.php no query is being produced so is_page() or is_category() or any query based conditional tag will never return true. A better way would be to include your files inside the ajax callback, meaning something like this: add_action(‘wp_ajax_PAGE_ONLY_ACTION’,’PAGE_ONLY_Function’); function PAGE_ONLY_Function(){ include TEMPLATEPATH . ‘/ajaxLoops/ajax-open_client_editform.php’; /** * do your page only ajax */ … Read more

WP_Query orderby breaks when using AJAX?

I believe Milo is right, it’s probably a filter affecting this. Ajax requests look like admin requests (that is, is_admin() returns true), so it’s possible that something is checking if is_admin() and adding the filter in those cases. You can set ‘suppress_filters’ => true in your args array and it will probably work. Note that … Read more