Skip to content

Instantly share code, notes, and snippets.

@jpalala
Created April 21, 2014 05:22
Show Gist options
  • Save jpalala/11133005 to your computer and use it in GitHub Desktop.
Save jpalala/11133005 to your computer and use it in GitHub Desktop.
simple wp wrapper - for external systems
<?php
class WPObj {
public $db;
public $prf;
public function __construct($pdoDB,$prefix = NULL) {
// save db object to our class
$this->db = $pdoDB;
if(!$prefix)
$this->prf = '';
else
$this->prf = $prefix;
}
}
public function getPosts($limit = 10) {
$results = $this->db->query("SELECT DISTINCT
post_title,
post_content,
(SELECT group_concat( ". $this->prf ."terms.name separator ', ')
FROM wp_terms
INNER JOIN ". $this->prf ."term_taxonomy on wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN ". $this->prf ."term_relationships wpr on wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
WHERE taxonomy= 'category' and ". $this->prf ."posts.ID = wpr.object_id) AS "Categories"
FROM wp_posts WHERE post_type = 'post'
ORDER BY post_title, post_content, post_date DESC LIMIT " . $limit;
return $posts[] = $results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment