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
}

Leave a Comment