2016-11-07 6 views
0

誰かがこれまで私がPHPを使い始めたばかりで助けてくれますか?Wordpressは税務署による投稿を取得します - 税務用語はページスラッグです

私は分類や用語を使用してカスタムカテゴリがあります。 すなわちMAIN GALLERY(カスタムカテゴリ) - ギャラリーワン(taxomony 1) - アルバムワン(用語1) - アルバムつ(用語2) - ギャラリー2(taxomony 1)

アルバム1(用語1)のすべての投稿を表示したいと思います。

私はこれまでのところ、このコードを持っている:スラグ名はフロントエンドに印刷されているが、ポストを返すために使用されていない、それはこのビット
'terms' => array_shift($terms)あります?

私は配列にTerm名を指定しても、これを動作させることができますが、私はそれをページのスラッグから読み込む必要があります。

私は非常にPHPに新しいし、おそらくどこかで構造が間違っている、ループなどを混乱させる何かをしました。どんな助けでも大歓迎です。

CODE:

<?php 

$terms = get_the_terms($post->ID, 'pubgal'); // get the term $term = array_shift($terms); 
echo $term->slug; 
$args = array(
    'tax_query' => array(
     array(
      'taxonomy' => 'pubgal', 
      'field' => 'slug', 
      'terms' => array_shift($terms) 
     ), 
    ), 
    'post_type' => 'gallery' 
); 
$query = new WP_Query($args); 
if ($query->have_posts()) { 
    $term = $query->queried_object; 
    while ($query->have_posts()) : 
     $query->the_post(); 
     the_title(); 
     the_content(); 
     the_post_thumbnail(); 
    endwhile; 
} 
//RESET YOUR QUERY VARS 
wp_reset_query(); 

?> 
+0

コード: <?php $ terms = get_the_terms($ post-> ID、 'pubgal'); //用語を取得 $ term = array_shift($ terms); echo $ term-> slug; $引数=配列( 'tax_query' =>配列( アレイ( '分類法' => 'pubgal' 'フィールド' => 'スラグ' '用語' => array_shift($用語) ) 、)、 'post_type' => 'gallery' ); $ query =新しいWP_Query($ args); if($ query-> have_posts()){ $ term = $ query-> queried_object; while($ query-> have_posts()):$ query-> the_post(); the_title(); the_content(); \t the_post_thumbnail(); endwhile; } //クエリバーをリセットする wp_reset_query(); ?> – Rachel

答えて

0

あなたがget_termsで​​を(持っているので、term_idを取得するために$termsをループする必要があります)(すべてthqeデフォルト値を使う場合は用語IDです、あなたは$でそれを取得します

fields='idsと入力すると、tax_queryに$ termsを直接(最終的には必要に応じてarray_shiftを使用して)質問することができます。

関連する問題