Site icon Hip-Hop Website Design and Development

How you can ignore WP_ERROR attributable to "get_the_excerpt" methodology in an AJAX name?

operate get_post_data(){
    $post_id = $_POST['post_id'];
    ...
    $information['title'] = get_the_title( $post_id );
    ...
    $information['excerpt'] = get_the_excerpt( $post_id );        
    ...            
    echo json_encode( $information );

    wp_die();

}

The above code reveals the scheme of the ajax name. Some information needs to be retriven from a submit given by its ID outdoors the LOOP. This appears to work when the content material fields like title and excerpt not empty. However when empty I get an Inner Server Error (500: admin-ajax.php not discovered). Once I debug the PHP code it appears an WP_ERROR to be thrown after calling "get_the_excerpt".

I simply needed to get some form of resolution like:

If (get_the_excerpt( $post_id ) returns an WP_ERROR) then let $information['excerpt'] = '';

Something I attempted f.e. strive{} catch{} will not work, additionally not after I insert this to initialize the loop:

setup_postdata($post_id); 

within the second line of the "get_post_data" operate