0

I am trying to have two different queries in my Loop, which is located in index.php. I am working with WP codex, but it isnt working. I want to have every post in its own special DIV later, so this is just start of my work.

The problem is, that the second part of code doesnt work, and I have no idea why. As far as I have read the codex, everything should be fine. Please help me.

 <div class="col1">  
        <?php
        $my_query = new WP_Query('category_A tym=featured&posts_per_page=1');
        while ($my_query->have_posts()) : $my_query->the_post();
            $do_not_duplicate = $post->ID;
            ?>
            <!-- Do stuff... -->
            <?php get_template_part('content', get_post_format()); ?>
        <?php endwhile; ?>

        <!--Over here everything works fine!-->



        <!--This code doesnt show up. It is supossed to show 1 post, only heading and date with author. But it doesnt show nothing at all.-->

        <?php
        $my_queryOne = new WP_Query('posts_per_page=1');
        while ($my_queryOne->have_posts()) : $my_queryOne->the_post();
            if ($post->ID == $do_not_duplicate)
                continue;
            ?>
            <!-- Do stuff... -->
            <h2 id="post-<?php the_ID(); ?>">
                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
                    <?php the_title(); ?></a></h2>
            <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
            <?php
        endwhile;
        ?>     

    </div>

2 Answers 2

1

WP_Query takes an array as a parameter - i.e.

$query = new WP_Query( array( 'category_name' => 'featured','posts_per_page' => 1 ));

Also, when running multiple queries - use wp_reset_postdata() after the first loop.

Great examples here:

https://codex.wordpress.org/Class_Reference/WP_Query

Sign up to request clarification or add additional context in comments.

Comments

1

Its probably best to review the coding guidelines that WordPress has laid out. You need to ensure that every open and close tag for inline PHP is on its own line.

Check here for reference:

https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#opening-and-closing-php-tags

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.