0

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' );
2

Found the solution, simple add " wp_reset_query(); " before the return

  • Since you're not really overwriting the main query it's more efficient to use wp_reset_postdata(). – Howdy_McGee Aug 23 '18 at 22:38
  • Thanks @Howdy_McGee Now I am understand better the solution. The wp_reset_query() solved the problem but I didn't understand why.However the codex explanation of the wp_reset_data() function has solved all my doubts and now I have a better understanding of what is happening. – Wilfred Aug 29 '18 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.