Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to do some query. Now i choosing from this variables. Which is from this queries is more faster. Which differences between them ?

function filter_where($where = '') {
     $where .= " AND post_date > '" . date('Y-m-d', strtotime('-10 days')) . "'";
     return $where;
} 

add_filter('posts_where', 'filter_where');
$my_query = new WP_Query( array( 'meta_key' => 'post_views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => 5 ) );
remove_filter( 'posts_where', 'filter_where' );

while ($my_query->have_posts()) : $my_query->the_post();

And this.

 function filter_where($where = '') {
      $where .= " AND post_date > '" . date('Y-m-d', strtotime('-10 days')) . "'";
      return $where;
}

add_filter('posts_where', 'filter_where');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$my_query = new WP_Query( "meta_key=post_views&orderby=meta_value_num&order=DESC&posts_per_page=5&paged=$paged" );
remove_filter( 'posts_where', 'filter_where' );

while ($my_query->have_posts()) : $my_query->the_post(); 
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

These queries are the same - the only difference being the syntax. There'll be no noticeable performance difference. I prefer the first for readability when it is formatted correctly.

(Also, the first query doesn't use the paged argument, so it won't 'paginate' - but I guess that was omitted by mistake).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.