Wordpress Query_Posts ()

Hey Guys,

I am currently using query_posts for a blog slider i have made in Owl, is it still ok to use query_posts() or is it better to use WP_Query? i have been told so and if so how easy is it to convert because my current code is :

<?php
                    query_posts('posts_per_page=-1');
                    while (have_posts()) : the_post();

                        $i = $wp_query->current_post;
                        echo ( 0 == $i % 3 ) ? '<div class="item">' : '';
                        ?>

                        <div class="blog-item">
                            <h3><?php the_title(); ?></h3>
                            <a href="<?php the_permalink(); ?>">learn more</a>
                        </div>

                        <?php
                        echo ( $wp_query->post_count == $i || 2 == $i % 3 ) ? '</div>' : '';
                    endwhile;
                    wp_reset_query();
                    ?>

It’s really not that hard, and I prefer it because I feel it gives me more options and control over my query. You would start it out like this (compare this code to yours):

<?php
	$args = array(
		'posts_per_page' => -1
	);
	
	$blog_query = = new WP_Query( $args );
	
	while ($blog_query->have_posts()) : $blog_query->the_post();

		// continue code here (you will need to change a few of these lines too)
?>

For more information, check out the WordPress documentation on WP-query. This page will list for you all the available parameters, etc available.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.