posts_per_page non funziona
Ecco la mia query personalizzata:
<?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 Query
$the_query = new WP_Query( $Poz );
// Il Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="Leggi l'articolo <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata(); ?>
Ho iniziato cercando di minimizzare le mie query. Ho trovato alcuni articoli a riguardo. Questo metodo significa eseguire solo due query.
Puoi controllarlo anche qui.
La domanda riguarda l'argomento posts_per_page. Perché non funziona? Penso sia a causa di
'no_found_rows' => true,
questo argomento. Significa che non c'è paginazione per la query. Ma come possiamo limitare il numero di post? O cosa possiamo usare invece di posts_per_page in questa query? Parliamone.
-- Aggiornamento --
Ho cambiato il metodo della query usando query_posts invece di new WP_Query:
<?php
# Query WordPress in cache
# 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="Leggi l'articolo <?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
è la stessa cosa? Questo aumenta il numero di query o no? Inoltre ho aggiunto quella riga ma i risultati mostrano lo stesso numero di post come la query principale

nopaging
dice a WordPress: senti amico, so che fai il paging di default, ma smettila e dammi semplicemente i miei X post. Quindi, meno query, suppongo.

Sono confuso ma non funziona comunque. :/
`<?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 );
// The 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(); ?>`

Aspetta un attimo. Questo non è il motivo. Mi sono completamente perso. Dovrebbe essere: $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 );
Il $Poz
dovrebbe essere args per il new WP_Query

Provalo per favore non funziona. Tutti i post arrivano (: La query non rispetta i numeri.

Non è questione di 'no_found_rows' => true,
ma di passare gli argomenti a new WP_Query

Dovremmo cambiare il metodo di query? Ad esempio usando get_posts(); o qualcos'altro invece di new Query
?

Dipende da te. Io userei WP_Query. Il punto è che $Poz
dovrebbe essere gli argomenti per la query, non una nuova query.

Ora credo di aver capito. Ecco il nuovo codice: https://gist.github.com/3951155 Ma dovresti sapere che quando aggiungi il parametro no-pagging non funziona di nuovo.

continuiamo questa discussione in chat

Non funziona per me. Utilizzo WP Query all'interno di uno shortcode [posts] creato da me. Gli attributi "posts_per_page" e "nopaging" vengono passati come attributi dello shortcode (tutto funziona qui) ma mi restituisce TUTTI i post.
