posts_per_page no funciona
Aquí está mi consulta personalizada:
<?php
$Poz = new WP_Query(array(
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
));
// La Consulta
$the_query = new WP_Query( $Poz );
// El Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="Leer el artículo <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata(); ?>
Empecé intentando minimizar mis consultas. Encontré algunos artículos sobre esto. Este método significa hacer solo dos consultas.
También puedes verificarlo aquí.
La pregunta es sobre el argumento posts_per_page. ¿Por qué no funciona? Creo que es por
'no_found_rows' => true,
este argumento. Significa que no hay paginación para la consulta. Pero ¿cómo podemos limitar el número de publicaciones? o ¿qué podemos usar en lugar de posts_per_page en esta consulta? Hablemos de esto.
-- Actualizado --
Cambié el método de consulta a query_posts en lugar de new WP_Query:
<?php
# Consultas WordPress en caché
# SE Disq : http://wordpress.stackexchange.com/questions/70424/posts-per-page-doesnt-work/70425
$Poz = array(
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
);
query_posts( $Poz ); while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="Leer el artículo <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>

Sí, usa 'nopaging' => true
http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
$Poz = array(
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'nopaging' => true,
);
$the_query = new WP_Query( $Poz );

'nopaging' => true
¿es lo mismo? ¿Esto genera más consultas o no? Además, agregué esa línea pero el número de resultados mostrados sigue siendo como en la consulta principal.

nopaging
le dice a WordPress: mira, sé que por defecto haces paginación, pero detén eso y solo dame mis X posts. Así que, supongo que menos consultas.

Estoy confundido pero tampoco funciona. :/
`<?php $Poz = new WP_Query(array( 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'nopaging' => true, )); $the_query = new WP_Query( $Poz );
// El Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?> yazısını oku."><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata(); ?>`

Espera un segundo. Esta no es la razón. Me lo perdí por completo. Debería ser: $Poz = array(
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false, 'nopaging' => true,
);
$the_query = new WP_Query( $Poz );
El $Poz
debería ser args para el nuevo WP_Query

Por favor pruébalo, no funciona. Todos los posts aparecen (: La consulta no respeta los números.

No se trata de 'no_found_rows' => true,
sino de pasar los argumentos a new WP_Query

¿Deberíamos cambiar el método de consulta? ¿Algo como usar get_posts(); o algo similar en lugar de new Query
?

Depende de ti. Yo usaría WP_Query. El punto es que $Poz
se supone que son argumentos para la consulta, no una nueva consulta.

Ahora lo entiendo, creo. Aquí está el nuevo código: https://gist.github.com/3951155 Pero debes saber que cuando añades el parámetro no-pagging no funciona de nuevo.

continuemos esta discusión en el chat

No funciona para mí. Utilizo WP Query dentro de un shortcode [posts] creado por mí. Los atributos "posts_per_page" y "nopaging" se pasan como atributos del shortcode (todo funciona aquí) pero me devuelve TODAS las publicaciones.
