My site is running Generate Press theme and using Elementor as page builder.
My goal is to created a shortcode that will display a CPT and it’s metafields. When i use the shortcode on a page it works fine. However when I use it under Elementor I get the following error when I try to edit the post in the backend:
“The Content Area Was Not Found in Your Page”
https://docs.elementor.com/article/56-content-area-not-found
Supposedly this is because the function the_content is missing.
I have tried adding the function to the shortcode, but still nothing. Elementor support wouldn’t help. Maybe one you can reason why this is happening. Here you have the code:
function vehiculos_func( $atts ){
$arg = array (
'post_type' => 'vehiculo'
);
$query = new WP_Query($arg);
if($query ->have_posts()) {
//echo "<ul>";
// echo '<div class="grid-container">';
$html ="<ul>";
$html .= '<div class="grid-container">';
while ($query ->have_posts()) {
$query->the_post();
$year = get_post_meta(get_the_id(), 'vehicle_year', true);
$kilometers = get_post_meta(get_the_id(), 'vehicle_kilometers', true);
$transmission = get_post_meta(get_the_id(), 'vehicle_transmission', true);
$doors = get_post_meta(get_the_id(), 'vehicle_doors', true);
$seats = get_post_meta(get_the_id(), 'vehicle_seats', true);
$power = get_post_meta(get_the_id(), 'vehicle_power', true);
$color = get_post_meta(get_the_id(), 'vehicle_color', true);
$fuel = get_post_meta(get_the_id(), 'vehicle_fuel', true);
$html .= '<span class="nombre">'.get_the_title().'</span>';
$html .= '<li class="grid-33">';
$html .= '<div class="vehiculo">';
$html .= '<div class="separa-20"></div>';
$html .= '<span class="nombre">'.get_the_title().'</span>';
$html .= '<p>'.get_the_content().'</p>';
$html .= '<span class="atributo">'.$kilometers.'| '.$fuel.'| '.'Año //'.$year.'</span>';
$html .= '<div class="separa-10"></div>';
$html .= '<span class="precio">Desde 4000€';
$html .= '<div class="separa-20"></div>';
$html .= '<button type="button" class="btn-small btn-default">Ver //Coches</button>';
$html .='</div>';
$html .='</li>';
}
$html .= '</div>';
$html .= "</ul>";
}
return $html;
}
add_shortcode( 'vehiculos', 'vehiculos_func' );
1 Answer
Found the solution, simple add ” wp_reset_query(); ” before the return