2013-08-02 3 views
0

У меня возникла проблема с пользовательским типом сообщения и пользовательскими таксономиями. Я создал пользовательский тип сообщения, называемый «галереи» и таксономии с именем «gallery_type». И я создал страницу под названием Галерея, в которой я загрузил все сообщения из галерей. И тогда я создал «сад» & «таксономический термин« дом »и присвоил 3-3 сообщения каждому« саду »&« дом ». И я связал термины таксономии «сад» и «дом» в качестве подменю в галерее, которая является моим нынешним родителем. Я хочу отображать сообщения в их соответствующих условиях. Но это не загрузка. Что я могу сделать ?? Мой код: 'Wordpress Тип пользовательских сообщений и пользовательская таксономия

$tax = 'gallery_type'; 
$terms = get_the_terms($post->ID, $tax); 
if($terms){ 
foreach($terms as $term){ 
$single = $term->name; 
?> 

    <?php 
    $args = array('post_type'=>'galleries', 
    'posts_per_page'=> -1, 
    'tax_query'=>array(
    array('taxonomy'=>'gallery_type', 
    'terms'=> $single) 
    ), 
    'order_by'=>'post_date'); 
    $query = new WP_Query($args); 
    if($query->have_posts()){ 
    while($query->have_posts()): 
    $query->the_post(); 
    $post_id = $post->ID; 
    ?> 
    <li class="thumb <?php echo $post_id; ?>" onclick="changeContent(<?php echo $post_id; ?>);"> 
    <?php if(has_post_thumbnail()) 
    the_post_thumbnail('gallery-thumb'); 
    ?> 

    <?php 
    endwhile; 
    wp_reset_query(); 
    } 
    else{ 
    _e('No image found in gallery'); 
    } 
    ' 

Any fix??? 

ответ

0

Попробуйте использовать вместо слизняка на имя термина таксономии.

$tax = 'gallery_type'; 
$terms = get_the_terms($post->ID, $tax); 
if($terms){ 
foreach($terms as $term){ 
$single = $term->slug; 

// Also instead of this query for the taxonomy, as you are on the taxonomy page, you should use $single = $wp_query->query_vars['taxonomy_name']; <- This is the slug of the current viewed taxonomy 

?> 

    <?php 
    $args = array('post_type'=>'galleries', 
    'posts_per_page'=> -1, 
    'tax_query'=>array(
    array('taxonomy'=>'gallery_type','field' => 'slug', 
    'terms'=> $single) 
    ), 
    'order_by'=>'post_date'); 
    $query = new WP_Query($args); 
    if($query->have_posts()){ 
    while($query->have_posts()): 
    $query->the_post(); 
    $post_id = $post->ID; 
    ?> 
    <li class="thumb <?php echo $post_id; ?>" onclick="changeContent(<?php echo $post_id; ?>);"> 
    <?php if(has_post_thumbnail()) 
    the_post_thumbnail('gallery-thumb'); 
    ?> 

    <?php 
    endwhile; 
    wp_reset_query(); 
    } 
    else{ 
    _e('No image found in gallery'); 
    } 
Смежные вопросы