Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. public function get_post_from_url(){
  2. global $wpdb;
  3. $postid = url_to_postid(esc_url("http://localhost/teln/web-security-privacy-not-trade-off-both-should-be-goal-engineers-say/"));
  4. $query = "
  5. SELECT ID, post_date, post_title, post_excerpt, post_type
  6. FROM $wpdb->posts
  7. WHERE $wpdb->posts.ID = %d
  8. AND $wpdb->posts.post_status = 'publish'
  9. LIMIT 1
  10. ";
  11. $sql = $wpdb->prepare($query, $postid);
  12. $results = $wpdb->get_results($sql);
  13.  
  14. return $results;
  15.  
  16. }
  17.  
  18.  
  19. public function process_post_data_and_return_json($results){
  20. $to_return = array();
  21. $post_date = get_the_date( "U", $results[0]->ID );
  22. $tags = get_the_tags( $results[0]->ID );
  23. $main_tag = "";
  24. if ( is_array( $tags ) ) {
  25. foreach ( $tags as $tag ) {
  26. if ( $tag->slug == 'featured' ) {
  27. $main_tag = 'Featured';
  28. } else if ( $tag->slug == 'highlight' ) {
  29. $main_tag = 'Highlight';
  30. }
  31. }
  32. }
  33.  
  34. $to_return['tag'] = $main_tag;
  35. $to_return['ID'] = $results[0]->ID;
  36. $to_return['date'] = date( "M j, Y", $post_date );
  37. $to_return['hour'] = date( "H:i", $post_date );
  38. $to_return['post_title'] = $results[0]->post_title;
  39. $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>" );
  40.  
  41. $response = json_encode($to_return);
  42.  
  43. return $response;
  44. }
  45.  
  46. 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 ) )
  47.  
  48. {"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