function get_post_data(){
$post_id = $_POST['post_id'];
...
$data['title'] = get_the_title( $post_id );
...
$data['excerpt'] = get_the_excerpt( $post_id );
...
echo json_encode( $data );
wp_die();
}
The above code shows the scheme of the ajax call. Some data should be retriven from a post given by its ID outside the LOOP. This seems to work when the content fields like title and excerpt not empty. But when empty I get an Internal Server Error (500: admin-ajax.php not found). When I debug the PHP code it seems an WP_ERROR to be thrown after calling "get_the_excerpt".
I just wanted to get some kind of solution like:
If (get_the_excerpt( $post_id ) returns an WP_ERROR) then let $data['excerpt'] = '';
Anything I tried f.e. try{} catch{} won’t work, also not when I insert this to initialize the loop:
setup_postdata($post_id);
in the second line of the "get_post_data" function