Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 ) ? "<span class='bbna-email-excerpt'>" . $results[0]->post_excerpt . "</span>" : "<span class='no-excerpt-warning'>NO EXCERPT FOUND!</span>" );
- $response = json_encode($to_return);
- return $response;
- }
- 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 ) )
- {"tag":"","ID":null,"date":"Jan 1, 1970","hour":"00:00","post_title":null,"post_excerpt":"NO EXCERPT FOUND!</span>"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement