In my theme I want to display thumbnail and title of posts of a certain category (ID=1). On click of the thumbnail the post with content,... should be shown. Since I added the wp_query part for the category filtering it always displays all posts of the the respective category if I click on one post. I already added wp_reset_postdata() and wp_reset_query() but it seems to have no effect. What else can I do to limit the displaying to the clicked post only and not the whole query?


        $general_post = new WP_query();
        if($general_post->have_posts()) {
            while($general_post->have_posts()) {
                get_template_part('content', get_post_format());

template file:

//template for preview on index
        <?php if (is_home() ) { ?>
                    <a href=<?php echo get_permalink();?>><?php the_post_thumbnail(array(300,600)); ?>
                        <h1 class="entry-title"><?php the_title()?></h1>
        <?php }

//template for whole post
        <?php if (!is_home() ) { ?>
            <?php the_post_thumbnail('full'); ?>>
            <?php the_title()?>
            <?php the_content(); ?>
        <?php } ?>

If this should be your main loop, the preferable way to modify the main loop is to use the pre_get_posts filter. For a secondary, it's okay to use WP_Query, but you're setting query arguments the wrong way. WP_Query expects an array of arguments.

$args = array(
    'cat' => 1
$general_posts = new WP_Query( $args );

You can read more about WP_Query here.

| improve this answer | |

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.