特定のカスタム投稿タイプのすべての投稿を一覧表示し、それらに添付されたカスタム分類用語で並べ替える方法はありますか?
例えば;
Taxonmy Term#1
 
投稿タイプ
投稿タイプ
投稿タイプ
分類用語#2
 
投稿タイプ
投稿タイプ
どんな助けでも大歓迎です。
ありがとう。
特定のカスタム投稿タイプのすべての投稿を一覧表示し、それらに添付されたカスタム分類用語で並べ替える方法はありますか?
例えば;
Taxonmy Term#1
 
投稿タイプ
投稿タイプ
投稿タイプ
分類用語#2
 
投稿タイプ
投稿タイプ
どんな助けでも大歓迎です。
ありがとう。
回答:
これを試して
$custom_terms = get_terms('custom_taxonomy');
foreach($custom_terms as $custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'custom_post_type',
        'tax_query' => array(
            array(
                'taxonomy' => 'custom_taxonomy',
                'field' => 'slug',
                'terms' => $custom_term->slug,
            ),
        ),
     );
     $loop = new WP_Query($args);
     if($loop->have_posts()) {
        echo '<h2>'.$custom_term->name.'</h2>';
        while($loop->have_posts()) : $loop->the_post();
            echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
        endwhile;
     }
}分類法のすべての用語を取得し、それらをループし、その用語に属する各投稿へのタイトルリンクを起動します。分類条件を並べ替える必要がある場合は、プラグインを使用して簡単に並べ替えることができます。分類法を並べ替えます。しかし、このプラグインは、上の表に(!)別の列を追加することに注意を払うの活性化および非アクティブ化すると、それを削除しません!
$custom_termsとforeach()、ちょうど定義'terms'したいスラグまたは任意に手動で。
                    特にエレガントなソリューションではありませんが、特定の用語に対してそれぞれ複数のクエリを作成して出力できます。うまくいけば、誰かが用語を自動的に引き出して出力/ソートを変更するより良い方法を思いつくことができます。しかし、これでうまくいくでしょう。
<?php
//First Query for Posts matching term1
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term1' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );
if ( have_posts() ) {
    $term = $query->queried_object;
    echo 'All posts found in ' . $term->name;
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}
//RESET YOUR QUERY VARS
wp_reset_query();
//Second Query for term2
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term2' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );
if ( have_posts() ) {
    $term = $query->queried_object;
    echo 'All posts found in ' . $term->name;
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}良いですね!GhostOneのソリューションは私が探していたものでした。私の状況では、カスタム投稿タイプは「minining_accidents」であり、これに関連付けられたカスタム分類は「accident-types」であり、その下に複数の用語がありました。私のアイデアは、このカスタム分類の用語で投稿のリストを表示するカスタムウィジェットを作成することでした。私の試運転で、それは私が欲しかったものを得ました。残りは小ぎれいでした。ここに私のコードがあります:
function fn_get_list_of_mining_accident_types()
{
    $custom_taxonomy='accident-types';  
    $custom_terms = get_terms($custom_taxonomy);    
    $str_return='<ul>';
    foreach($custom_terms as $custom_term) 
    {
        wp_reset_query();
        $args = array(
            'post_type' => 'minining_accidents',
            'tax_query' => array(               
                array(
                    'taxonomy' => $custom_taxonomy,
                    'field' => 'slug',
                    'terms' => $custom_term->slug,
                ),
            ),
        );  
        $loop = new WP_Query($args);
        $term_name=$custom_term->name;
        $term_slug=$custom_term->slug;
        $term_link=get_term_link($term_slug, $custom_taxonomy);
        $str_return.='<li><a href="'.$term_link.'">'.$term_name.'</a>';
        if($loop->have_posts()) 
        {
            $str_return.='<ol>';
            while($loop->have_posts()) : $loop->the_post();
                $str_return.='<li><a href="'.get_permalink().'">'.get_the_title().'</a></li> ';
            endwhile;
            $str_return.='</ol>';           
         }
         $str_return.='</li>';
    }
    $str_return.='</ul>';
    return $str_return;
}はい!コードをさらに改善するオプションが常にあります。
カスタム分類からのカスタム投稿のリストを表示するには
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'your-custom-taxonomy',
            'field' => 'slug',
            'terms' => array( 'your-term' )
        ),
    ),
    'post_type' => 'your-post-type'
);
$loop = new WP_Query($args);
     if($loop->have_posts()) {
    $term = $wp_query->queried_object;
     while($loop->have_posts()) : $loop->the_post();
        //Output what you want      
   echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
      endwhile;
}タイトル