2016-11-07 45 views
0

有人可以帮助我,因为我是PHP新手?Wordpress通过税务条款获得帖子 - 税务条款是页面slug

我有分类及术语定义类别: 即 主要画廊(自定义分类) - 画廊之一(taxomony 1) - 相册一(期限1) - 相册两(任期2) - 图库两个(taxomony 1)

我想显示专辑1(术语1)中的所有帖子。

我有这样的代码至今:嵌塞名称打印在前端而不是被用于返回岗位,是不是该位
'terms' => array_shift($terms)

我可以得到这个工作,如果我指定在数组中的术语名称,但我需要它从页slu读取。

如前所述,我对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

CODE: <?php $ terms = get_the_terms($ post-> ID,'pubgal'); //获得期限 $ term = array_shift($ terms); echo $ term-> slug; 的$ args =阵列( 'tax_query'=>数组( 阵列( '分类'=> 'pubgal', '字段'=> '蛞蝓', '术语'=> array_shift($术语) ) ,), '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_title(); the_content(); \t the_post_thumbnail(); end; } //重置您的查询变量 wp_reset_query(); ?> – Rachel

回答

0

您可以通过$terms需要循环得到term_id,因为你必须在get_terms​​()(全部是thqe默认值如果术语ID,你会得到$它term-> term_id)

如果你放fields='ids你可以直接询问tax_query $条款(如果需要的话最终会带有array_shift)。