Ich bekomme kein Ergebnis von PHP-function, die JSON-codiert ist

Also versuche ich eine Reihe von Post-Daten zu erstellen. Aber wenn ich es kodierte, bekomme ich die Postobjektdaten nicht von der database zurück.

Hier sind meine zwei functionen

public function get_post_from_url(){ global $wpdb; $postid = url_to_postid(esc_url("http://localhost/teln/web-security-privacy-not-trade-off-both-should-be-goal-engineers-say/")); $query = " SELECT ID, post_date, post_title, post_excerpt, post_type FROM $wpdb->posts WHERE $wpdb->posts.ID = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1 "; $sql = $wpdb->prepare($query, $postid); $results = $wpdb->get_results($sql); return $results; } public function process_post_data_and_return_json($results){ $to_return = array(); $post_date = get_the_date( "U", $results[0]->ID ); $tags = get_the_tags( $results[0]->ID ); $main_tag = ""; if ( is_array( $tags ) ) { foreach ( $tags as $tag ) { if ( $tag->slug == 'featured' ) { $main_tag = 'Featured'; } else if ( $tag->slug == 'highlight' ) { $main_tag = 'Highlight'; } } } $to_return['tag'] = $main_tag; $to_return['ID'] = $results[0]->ID; $to_return['date'] = date( "M j, Y", $post_date ); $to_return['hour'] = date( "H:i", $post_date ); $to_return['post_title'] = $results[0]->post_title; $to_return['post_excerpt'] = ( ! empty( $results[0]->post_excerpt ) ? "" . $results[0]->post_excerpt . "" : "NO EXCERPT FOUND!" ); $response = json_encode($to_return); return $response; } 

Wenn ich diese functionen drucke, erhalte ich Folgendes:

Für die erste function ist dies das Ergebnis

 Array ( [0] => stdClass Object ( [ID] => 85332 [post_date] => 2015-05-27 06:01:38 [post_title] => Web Security, Privacy Not Trade-Off, Both Should Be Goal, Engineers Say [post_excerpt] => Building trust in the Internet requires a concerted effort to bolster security and user privacy, technical policy panelists said May 25 at an International Telecommunication Union event in Geneva. [post_type] => post ) ) 

Für die zweite function ist dies das Ergebnis:

 {"tag":"","ID":null,"date":"Jan 1, 1970","hour":"00:00","post_title":null,"post_excerpt":"NO EXCERPT FOUND!"} 

Solutions Collecting From Web of "Ich bekomme kein Ergebnis von PHP-function, die JSON-codiert ist"