Domanda

  • Ho 2 doganale di tipo post: "Artista" e "concerto",
  • il "Concerto" di tipo messaggio personalizzato è il figlio del "Artist" Tipo di messaggio personalizzato,
  • l ' "artista" tipo di messaggio personalizzato ha una tassonomia "genere".

Quello che sto cercando di fare (per esempio):. List tutti i concerti che appartengono ad artisti del "pop" genere

Questa è la domanda del mio sogno:

SELECT * FROM posts WHERE post_type = "concert" AND post_parent_term = "pop"

Credo che attualmente non esiste una cosa come la post_parent_term , spero mi sbaglio ... (So ??che posso aggiungere la tassonomia "genere" per il "Concerto" tipo di messaggio personalizzato e voilà! Ma sono davvero curioso di sapere se c'è un altro modo per raggiungere questo obiettivo).

Grazie di anticipo.

È stato utile?

Soluzione

Quello che sto cercando di fare (per esempio): elencare tutti i concerti che appartengono alla artisti del genere "pop".

Si può farlo in due fasi:

// 1. Get all the pop artist IDs
$artist_ids = get_posts( array(
  'fields' => 'ids',
  'post_type' => 'artist',
  'genre' => 'pop'
) );

// 2. Get all the concerts associated to those artists
$artist_ids = implode( ',', array_map( 'absint', $artist_ids ) );

$concerts = $wpdb->get_results( "
  SELECT * FROM $wpdb->posts
  WHERE post_type = 'concert'
  AND post_status = 'publish'
  AND post_parent IN ({$artist_ids})
  ORDER BY post_date DESC
" );

C'è un argomento post_parent in WP_Query, ma non accetta una matrice , quindi l'interrogazione diretta.

Altri suggerimenti

La pagina padre è memorizzato in $ post-> post_parent

Quindi, si può semplicemente prendere il parent post in quel modo, e poi chiedere per essa la tassonomia / categoria / info tag.

Non sono sicuro se la strada giusta, ma è possibile creare cicli annidati:

// prima ottenere tutti gli artisti con il termine pop

$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => 'pop'
        ))
    'post_type' => 'Artist',
    'posts_per_page' => -1
    );
$Artists = new WP_Query( $args );
//loop through them and get there child posts of concerts 
if ( $Artists->have_posts() ) { 
    while ( $Artists->have_posts() ) {
        $Artists->the_post();
        $last_artist = $post;
        $Concerts = new WP_Query();
        $Concerts->query(array(
                        'post_type' => 'concert',
                        'posts_per_page' => -1,
                        'post_parent' => $post->ID
                        ));
        while ( $Concerts->have_posts() ) {
            $Concerts->the_post();
            //do concert stuff here
            //the_title();
            //the_content();
        }
        wp_reset_postdata();
        $post = $last_artist;
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top