Want more features on Pastebin? Sign Up, it's FREE!
Guest

Wordpress SQL / PHP

By: eberger on Nov 27th, 2012  |  syntax: PHP  |  size: 0.87 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. require_once('wp-load.php');
  3. $query = "
  4. SELECT p.post_name AS url, wpr.object_id AS PostID, p.post_date AS Date, wp_users.user_nicename AS Author, p.post_title AS Title,  group_concat(wp_terms.name ORDER BY wp_terms.name ASC separator ', ') AS Categories
  5. FROM wp_terms
  6. INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
  7. INNER JOIN wp_term_relationships wpr ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
  8. INNER JOIN wp_posts p ON p.ID = wpr.object_id
  9. INNER JOIN wp_users on wp_users.ID = p.post_author
  10. WHERE taxonomy = 'category'
  11. AND p.post_type = 'post'
  12. AND p.post_status = 'publish'
  13. AND p.post_date LIKE '2012%'
  14. GROUP BY wpr.object_id
  15. ORDER BY post_date DESC
  16. LIMIT 0 , 5000";
  17.  
  18. $sth = mysql_query($query);
  19. $rows = array();
  20. while($r = mysql_fetch_assoc($sth)) {
  21.     $rows[] = $r;
  22. }
  23.  
  24. print strip_tags(json_encode($rows));
  25.  
  26. ?>
clone this paste RAW Paste Data