0

I'm trying to display specific posts based on an ID of a post. I got it working with 2 posts and I will get it working for the 10 posts that I need it for, but it's going to be a lot of code and I feel like it's not the most efficient way but this is where my PHP skills end. Any help is appreciated!

<?php
$args1 = array( 'post__in' => array(26844,26829), 'post_type' => 'wedstrijd', 'post_status' => 'published', );
$args2 = array( 'post__in' => array(26831,26846,26859), 'post_type' => 'wedstrijd', 'post_status' => 'published', );
$shquery1 = new WP_Query( $args1 );
$shquery2 = new WP_Query( $args2 );

if ( $shquery1->have_posts() && is_single( 28522 ) ) {
    while ( $shquery1->have_posts() ) {
        $shquery1->the_post();
        echo '<div><div class="wed_thumb wed_thumb_st"><a href="' . get_permalink() . '"><div class="wed_thumb-a">' . get_the_post_thumbnail() . '</div><div class="wed_thumb-title"><div class="wed_thumb-divider"></div>' . get_the_title() . '</div></a></div></div>';
    }
}
elseif ( $shquery2->have_posts() && is_single( 28283 ) ) {
    while ( $shquery2->have_posts() ) {
        $shquery2->the_post();
        echo '<div><div class="wed_thumb wed_thumb_st"><a href="' . get_permalink() . '"><div class="wed_thumb-a">' . get_the_post_thumbnail() . '</div><div class="wed_thumb-title"><div class="wed_thumb-divider"></div>' . get_the_title() . '</div></a></div></div>';
    }
} else {
    // no posts found
}

wp_reset_postdata();
?>
  • Hi, where do you get these new posts from? How do you know which posts to show? – Krzysiek Dróżdż Oct 17 at 5:38
  • With 'post__in' I query the ID's of the posts I want to show. I just know them by ID because it's very specific. – user1081953 Oct 17 at 8:46

Your Answer

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

Browse other questions tagged or ask your own question.