Skip to content

Instantly share code, notes, and snippets.

@jesse1981
Created April 19, 2013 05:57
Show Gist options
  • Save jesse1981/5418404 to your computer and use it in GitHub Desktop.
Save jesse1981/5418404 to your computer and use it in GitHub Desktop.
Wordpress function for retrieving all key/value pairs for a specific content-type. See: http://code.google.com/p/wordpress-custom-content-type-manager/
function getCustomTypeData($name) {
global $wpdb;
$returnValues = array();
$sql = "SELECT id, post_title, post_status, post_author, post_content FROM wp_posts WHERE post_title<>'Auto Draft' AND post_status='publish' AND post_type='$name'";
$customPosts= $wpdb->get_results($sql);
$count = 0;
foreach ($customPosts as $post) {
$returnValues[$count]["id"] = $post->id;
$returnValues[$count]["title"] = $post->post_title;
$returnValues[$count]["content"] = $post->post_content;
$returnValues[$count]["status"] = $post->post_status; // Publish = visible
$returnValues[$count]["author"] = $post->post_author; // Publish = visible
$customMetas = $wpdb->get_results("SELECT * from wp_postmeta WHERE post_id=".$post->id);
foreach ($customMetas as $meta) {
$returnValues[$count][$meta->meta_key] = $meta->meta_value;
}
$count++;
}
return $returnValues;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment