Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<?php $fields = get_post_custom($ID); ?>

This will fetch the custom fields ($key => $value) for $ID in to the array $fields.

I want ALL the fields (both custom & standard WP fields) associated with the $ID in one array $fields_all. How to do this in a simpler way?....is there a single function available in WP?

share|improve this question

migrated from stackoverflow.com Aug 1 '11 at 5:03

This question came from our site for professional and enthusiast programmers.

1 Answer 1

there is no single function you can use but you can create your own something like:

function get_all_post_fields($post_id){
    $p['standard'] = get_post($post_id, ARRAY_A);
    $p['meta'] = get_post_custom($post_id);
    return $p;
}

then once you have this in your functions.php file you can use it:

$fields_all = get_all_post_fields($ID);

Update:

If you have just the title then i have a simple function i use a lot to get the post id by the title:

function get_post_ID_by_title($page_title) {
    global $wpdb;
        $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title ));
        if ( $post_id )
            return post_id;
    return false;
}

usage: $post_id = get_post_ID_by_title("this is my title");

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.