Come interrogare post personalizzati e post regolari in WordPress

3 mar 2011, 18:43:14
Visualizzazioni: 16.5K
Voti: 3

Voglio popolare la sezione "Notizie Greenway" su questa pagina con i tre ultimi titoli sia dalla sezione Stampa che dal blog del sito.

Il blog è un blog WordPress standard e attualmente sto usando questo codice per ottenere i risultati:

<?php query_posts('cat=3&posts_per_page=3'); ?> 

La pagina Stampa è un custom post type. Posso far funzionare anche questo codice:

<?php
   query_posts( array( 'post_type' => 'portfolio', 'toolkit' => '2011' ) );
   // il loop inizia qui
   if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

È possibile fare entrambe le cose insieme?

2
Commenti

dai un'occhiata a http://codex.wordpress.org/The_Loop#Multiple_Loops

Bainternet Bainternet
3 mar 2011 19:06:27

ho aggiunto una risposta che presuppone che tu voglia mostrare i post e il tuo CPT nello stesso loop

anu anu
3 mar 2011 19:12:47
Tutte le risposte alla domanda 1
2

Ci sei quasi, devi solo dire a WP che vuoi interrogare sia i post che il tuo CPT Press.

Quindi:

query_posts( array( 'post_type' => array('posts', 'portfolio'), ...);

dove portfolio è il nome del tuo custom post type.

La relativa pagina del Codex

[Aggiornamento]

Ecco come dovrebbe essere la query

<?php

  $args = array('post_type'=>array('posts', 'portfolio'));

  query_posts($args);

  if ( have_posts() ) : while ( have_posts() ) : the_post();

?>
3 mar 2011 19:11:43
Commenti

Grazie per tutto l'aiuto. Sì, voglio che sia nello stesso loop. @Anu: Ho provato a seguire il suggerimento. Questo è il codice che ho creato. <?php query_posts ( array('post_type' => array('cat=1', 'portfolio', 'Year of Article' => '2011' ) )); //loop if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> Purtroppo, mostra solo il custom post type (Press Articles) e non i post. http://www.brooklyngreenway.org/?page_id=1037&preview=true @Anu, ho fatto qualcosa di sbagliato? Grazie per qualsiasi aiuto.

Jeff Tancil Jeff Tancil
4 mar 2011 21:13:52

Ho aggiornato la mia risposta, ma hai aggiunto alcuni parametri extra (es. Year of Article) che non riguardano la domanda originale

anu anu
8 mar 2011 15:22:34