• Hi, just joined so apologies if this is in the wrong section.

    I’m new to WordPress and I’m building a custom theme from scratch.

    I would like to know If my loops are “best practice” or if they will slow my site down.

    A brief description then some of my code.

    Basically on my index.php there are 3 loops.

    1. Is the image slider that displays 4 posts and custom post types from the featured category.

    2. Displays 3 custom posts (portfolio_item).

    3 Displays 3 blog posts.

    Now the following code works, but I would like to know if it will be slow or inefficient.

    1.

    <?php query_posts( array( 'post_type' => array( 'post', 'portfolio_item'), 'category__in' => array(10), 'posts_per_page' => 4 ) ); ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <?php endwhile; ?>

    2.

    <?php rewind_posts(); ?> <?php $loop = new WP_Query( array( 'post_type' => 'portfolio_item', 'posts_per_page' => 3 ) ); ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <?php endwhile; ?>

    3.

    <?php rewind_posts(); ?> <?php $loop = new WP_Query( array( 'posts_per_page' => 3 ) ); ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <?php endwhile;?>

    Sorry for the wall of text, my question. Is this the right approach?

    Thanks in advance.

  • The topic ‘Custom loops best practice?’ is closed to new replies.