jesse1981
4/19/2013 - 5:57 AM

Wordpress function for retrieving all key/value pairs for a specific content-type. See: http://code.google.com/p/wordpress-custom-content

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;

}