wp query - Loop returning only 1 result

I am not sure as to why when I run my loop only 1 result returns. Here is my code:<?phpif ( is_front_page() &&

I am not sure as to why when I run my loop only 1 result returns. Here is my code:

    <?php
    if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
        // Include the featured content template.
        get_template_part( 'featured-content' );
    }

            if ( is_home() ) {
                query_posts( "page_id=5" );
            }

    $args2 = array(
        "page_id" => 5
    );
    $wp_query2 = new WP_Query($args2);
    if ( $wp_query2->have_posts() ) :
                // Start the Loop.
                while ( $wp_query2->have_posts() ) : the_post();

                    $wp_query2->the_post();
                    //echo '<h1>'.get_the_title().'</h1>';
                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                     get_template_part( 'content', get_post_format() );

                endwhile;
                //wp_reset_post_data();
                // Previous/next post navigation.
                twentyfourteen_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( 'content', 'none' );

            endif;

$args = array(
        "ord" => "asc",
        "order_by" => "title",
        "cat" => 2,
        "posts_per_page" => 10,
        );
        $wp_query = new WP_Query($args);
            if ( $wp_query->have_posts() ) :
                // Start the Loop.
                while ( $wp_query->have_posts() ) : the_post();

                    $wp_query->the_post();
                    //echo '<h1>'.get_the_title().'</h1>';
                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                     get_template_part( 'content', get_post_format() );

                endwhile;
                //wp_reset_post_data();
                // Previous/next post navigation.
                twentyfourteen_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( 'content', 'none' );

            endif;
?>

By the way I have two loops and it is the second loop that I need to return multiple results. I am also running this code in index.php of my theme and it is based off of twentyfourteen.

I am not sure as to why when I run my loop only 1 result returns. Here is my code:

    <?php
    if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
        // Include the featured content template.
        get_template_part( 'featured-content' );
    }

            if ( is_home() ) {
                query_posts( "page_id=5" );
            }

    $args2 = array(
        "page_id" => 5
    );
    $wp_query2 = new WP_Query($args2);
    if ( $wp_query2->have_posts() ) :
                // Start the Loop.
                while ( $wp_query2->have_posts() ) : the_post();

                    $wp_query2->the_post();
                    //echo '<h1>'.get_the_title().'</h1>';
                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                     get_template_part( 'content', get_post_format() );

                endwhile;
                //wp_reset_post_data();
                // Previous/next post navigation.
                twentyfourteen_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( 'content', 'none' );

            endif;

$args = array(
        "ord" => "asc",
        "order_by" => "title",
        "cat" => 2,
        "posts_per_page" => 10,
        );
        $wp_query = new WP_Query($args);
            if ( $wp_query->have_posts() ) :
                // Start the Loop.
                while ( $wp_query->have_posts() ) : the_post();

                    $wp_query->the_post();
                    //echo '<h1>'.get_the_title().'</h1>';
                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                     get_template_part( 'content', get_post_format() );

                endwhile;
                //wp_reset_post_data();
                // Previous/next post navigation.
                twentyfourteen_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( 'content', 'none' );

            endif;
?>

By the way I have two loops and it is the second loop that I need to return multiple results. I am also running this code in index.php of my theme and it is based off of twentyfourteen.

Share Improve this question edited Dec 29, 2014 at 4:17 Mayeenul Islam 12.9k21 gold badges85 silver badges169 bronze badges asked Dec 28, 2014 at 21:02 lordsnowgooselordsnowgoose 113 bronze badges 1
  • you have a duplicate/wrong ``the_post();` in this line: while ( $wp_query->have_posts() ) : the_post(); - tryand remove that. how many posts are you expecting to see? – Michael Commented Dec 29, 2014 at 12:10
Add a comment  | 

1 Answer 1

Reset to default 1

Near the top of your code, you have wp_reset_postdata();.

As explained in the Functional Reference it alter the main loop and should be avoided. Looks like that's what's causing your issue.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744991693a4604945.html

相关推荐

  • wp query - Loop returning only 1 result

    I am not sure as to why when I run my loop only 1 result returns. Here is my code:<?phpif ( is_front_page() &&

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信