Answer the question
In order to leave comments, you need to log in
What is the difference between query_posts and new WP_Query?
Are there any differences in the entry:
<?php
query_posts('post_type=services&posts_per_page=-1' );
if (have_posts()) : while (have_posts()) : the_post();
...
<?php
$args = array('post_type' => 'services', 'posts_per_page' => '-1');
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
Answer the question
In order to leave comments, you need to log in
Don't use query_posts,
it re-runs queries against the database and overrides the global WP_Query
. From off. documentation:
Use get_posts или pre_get_posts
- This is a wrapper WP_Query
that simplifies the selection of posts and will not change global variables, it still defines some default arguments, which makes it easier to select.
For a more flexible selection, useWP_Query
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question