Wordpress - Return all custom meta data for one custom post type

If all of your custom post type posts have all meta fields that you need then you can use the fields argument and set it to ids which will work much faster for example:

//get your custom posts ids as an array
$posts = get_posts(array(
    'post_type'   => 'your_post_type',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'fields' => 'ids'
    )
);
//loop over each post
foreach($posts as $p){
    //get the meta you need form each post
    $long = get_post_meta($p,"longitude-key",true);
    $lati = get_post_meta($p,"latitude-key",true);
    $name = get_post_meta($p,"name-key",true);
    //do whatever you want with it
}

This code will give you all the posts with a longitude, latitude, and name assigned. Then you can loop through them to do your output and such.

$args = array(
    // basics
    'post_type'   => 'your_post_type',
    'post_status' => 'publish',

    // meta query
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key'     => 'longitude-key',
            'value'   => '',
            'compare' => 'NOT'
        ),
        array(
            'key'     => 'latitude-key',
            'value'   => '',
            'compare' => 'NOT'
        ),
        array(
            'key'     => 'name-key',
            'value'   => '',
            'compare' => 'NOT'
        ),
    )
);
$posts = new WP_Query( $args );

Naturally you're gonna needa modify that, and I strongly recommend reading the WP_Query documentation to get that tuned exactly how you want, but that'll do it for you. If you use that on a template, the whole thing should be a piece of cake.


Why not use get_metadata()?

If you pass the properly parameters you get all the meta attributes of a post (custom or not).

Example:

$META_ATTRIBUTES = get_metadata( 'post', get_the_ID(), '', true );

Note that I didn't use my cpt machine name as first parameter; you have to use 'post' or the function will return nothing.

Setting the third parameter (meta key) to an empty string you are telling to the function to retrieve all the meta attributes of the post.