How to retrieve custom field types for all posts in WordPress/PHP?

Custom fields are saved as “post meta” which is stored in wp_postmeta.

To retrieve them, you use the get_post_meta() function as follows:

$value = get_post_meta( $post_id, $meta_key, $single );

$single will almost always be set to true if you’re working string data. Unfortunately, it defaults as false, so if you’re retrieving the data as a string, you need to specify this as true:

$value = get_post_meta( $post_id, $meta_key, true );

You didn’t really give too much info about the data, but let’s assume it’s all string data and you want to retrieve it in your function. Here’s your function getting each of these and putting it into an array as a result:

function get_down_latest_videos( $post_id ) {             
     $meta_keys = array( 'broadview_updated', 'description_en', 'description_fr', 'description_short_en', 'description_short_fr', 'episode_id', 'title_short_en', 'title_short_fr' );

     foreach ( $meta_keys as $meta_key ) {
          $my_video_data[ $meta_key ] = get_post_meta( $post_id, $meta_key, true );
     }

     return $my_video_data;
}

To use it, if you pass the post ID to get_down_latest_videos( $post_id ) (where $post_id is the ID of your specific post), you’ll get back an array with the values of your custom fields where the array is keyed by the post meta key.

Update:

Now, if you want to loop through all of the ‘absf-episodes’ posts, you can set up a query like the following:

$query = new WP_Query(array(
    'post_type'      => 'absf-episodes',
    'post_status'    => 'publish'
    'posts_per_page' => -1,  // This gets "ALL" instead of limiting the results
));

while ( $query->have_posts() ) {
    $query->the_post();
    $post_id = get_the_ID();

    // You are now looping through each 'absf-episodes' by $post_id.
    // This example just spits out the post meta results for each post:
    echo '<pre>';
    $post_meta = get_down_latest_videos( $post_id );
    print_r( $post_meta );
    echo '</pre>';

}

Depending on where you use something like this, you may need to use wp_reset_query() before or after this loop (or possibly both).