I want to create a wordpress shortcode which makes a card carousel using posts

Viewed 18

I have tried using pre made templates but the result ends up being a bunch of content from the actual page that it is hosted on not the word press posts what should I do. Below is code to get the actual post on the page.

**function latestposts() {
    $html .= '';

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    // echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        $html .= '<h1>' .  get_the_title() . '</h1>';
    }
return $html;
} else {
    $html .= '<h1>no posts</h1>';
    return $html;
}
/* Restore original Post Data */
wp_reset_postdata();
}
add_shortcode( 'latestposts', 'latestposts' );**
0 Answers
Related