Your have two major issues here
-
The string you are building is correct, but it gets overriden on each iteration of the loop, which at the end will only hold the info from the last post. You need to define your variable outside the loop and then concatenate your info to that variable across the entire loop in order for you to display all postdata from all posts
-
You are returning the wrong info. You are returning post id after the first iteration of the loop. Your should be returning your string with post info outside the loop
I think your code should look like this:
add_shortcode('sedan-tabs','build_sedan_tabs');
function build_sedan_tabs(){
$querySedans="";
$args1 = array(
'post_type' => 'inventory',
'meta_key' => 'vehicle-type',
'meta_value' => 'Sedan',
'posts_per_page' => '4'
);
$query1 = new WP_Query($args1);
while ( $query1->have_posts() ) {
$query1->the_post();
$currentPostID = get_the_id();
$vehicleImg = get_post_meta($currentPostID,'vehicle-images', true);
$querySedans .= '<div class="col-sm-3"><div class="display-car"><img src="' . $vehicleImg . '"/>' .
'<h3>' . get_post_meta($currentPostID,'vehicle-year', true) . ' ' .
get_post_meta($currentPostID,'vehicle-make', true) . ' ' .
get_post_meta($currentPostID,'vehicle-model', true) .'</h3><p>' .
get_post_meta($currentPostID,'vehicle-mileage', true) . ' ' .
get_post_meta($currentPostID,'vehicle-transmission', true) . '<br /><strong>' .
get_post_meta($currentPostID,'vehicle-retail-price', true) . '</strong></p></div></div><a href="' . get_permalink($currentPostID, false) . '"></a>';
}
return $querySedans;
}