2013-08-16 11 views
5

Sto tentando di visualizzare un tipo di post personalizzato con tassonomia personalizzata, ma non ho fortuna. Non sta arrivando nulla Apprezzo qualsiasi aiuto.Tassonomia personalizzata WP_Query

Post Tipo = galleria

personalizzato Tassonomia slug = photoarea

Il 'photoarea' Voglio visualizzare = quarta

enter image description here

<?php 

$args = array( 
       'post_type' => 'gallery', 
       'tax_query' => array(
        array(
         'taxonomy' => 'photoarea', 
         'field' => 'fourth', 
         ) 
       ), 
       'posts_per_page' => 10, 
      ); 

$the_query = new WP_Query($args); 


if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 

    the_post_thumbnail(); 

endwhile; endif; 

wp_reset_query(); 

?> 

risposta

1

se la mia comprensione è giusto, che hai bisogno di ottenere la tassonomia personalizzata con il seguente codice, invece di field tu devono utilizzare term per ottenere i messaggi Quarto

<?php 

$args = array( 
       'post_type' => 'gallery', 
       'tax_query' => array(
        array(
         'taxonomy' => 'photoarea', 
         'term' => 'fourth', 
         ) 
       ), 
       'posts_per_page' => 10, 
      ); 

$the_query = new WP_Query($args); 


if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 

    the_post_thumbnail(); 

endwhile; endif; 

wp_reset_query(); 

?> 
+0

Non funziona per me. Attiva un avviso PHP. –

+0

hai bisogno di 'campo' => 'lumaca' e 'termini' => 'quarto' per ottenere questo lavoro, non 'termine'. –

1

È possibile utilizzare sotto frammento di codice:

$the_query = new WP_Query('post_type=gallery&photoarea=fourth'); 

e poi il ciclo while.

-2
$args = array('post_type' => 'gallery','posts_per_page'=>'-1','tax_query' => array(array(
             'taxonomy' => 'photoarea', 
             'field' => 'term_id', 
             'terms' => $your_term_id, 
            ), 
           ), 
          ); 
Problemi correlati