Loop in elementor custom widget not working

Question

I have a custom made widget for elementor, but my problem is that my loop to get posts doesn’t work properly. Currently, it returns the title of the page where the widget was inserted, doesn’t show the actual posts. Here’s the relevant part of my code:

    $args  = array(
        'posts_per_page'  => 12,
        'category_name'   => 'featured',
        'orderby'         => 'post_date',
        'order'           => 'ASC',
        'post_type'       => 'post',
        'suppress_filters' => true ); 
    $posts = get_posts($args);
        foreach ($posts as $post) :




            echo '<div class="posts-carousel swiper-container">';
            echo '<div class="swiper-wrapper">';

            echo    '<div class="swiper-slide carousel-post" style="background:url(';
            echo the_post_thumbnail('large');
            echo ');"><div class="text">';
            echo the_title();
            echo '</div><div class="overlay"></div></div>';

            echo '</div>';

            echo    '<div class="swiper-pagination"></div>';

            echo    '<div class="swiper-button-prev"></div>';
            echo    '<div class="swiper-button-next"></div>';
            echo '</div>';

        endforeach;

Anyone knows how could I make it work?

0
, , , , lastnoob 2 years 2019-10-24T17:00:53-05:00 0 Answers 65 views 0

Leave an answer

Browse
Browse