Using a WP Query for a carousel slider

I made a Custom Field in my Posts to which Trip a single Post is depending. So, for example, I made a road trip and for every city, there is a post.

Now, after collecting all written posts of a single trip into one wp query I want to display them in a kind of carousel so the user can see which other cities I traveled to in my trip.

Any suggestions what to use here? I am really stuck for around a week or so.

Btw I am not the best coder but I do my very best =)

Thanks and Cheers Stefan

1 answer

  • answered 2018-10-11 20:47 Adanzilla

    Hope it helps...

    <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <!-- Getting all the cities of the travel -->
        <?php $collection_of_cities_by_travel = get_post_meta( get_the_ID(), 'city_visited', false ); ?>
        <?php if( $collection_of_cities_by_travel ) : ?>
            <ul class="slick-slider"> <!-- 100% recomended-->
            <?php foreach ( $collection_of_cities_by_travel as $city ): $city_post = get_the_post( $city ); ?>
                <!-- Print the detail of every single city (post) in the travel -->
                <li class="slide">
                    <a href="<?php echo get_the_permalink( $city_post->ID ); ?>">
                        <?php echo get_the_post_thumbnail( $city_post->ID, 'post-thumbnail' ); ?>
                        <?php echo get_the_title( $city_post->ID ); ?>
            <?php endforeach ?>
        <?php endif; ?>
    <?php endwhile; ?>