好的,所以我可以正确显示所有内容,但如果自定义字段'Non-Marine'
的字段'value'
中有条件字词"item_tags"
以外的字词,则不会显示这些字词。
基本上我正在寻找帖子:
1.自定义 post_type - ait-dir-item
2.自定义现场位置 - annapolis
3.自定义字段item_tags - 非海事(此值在逗号分隔的其他条款中)
我也不确定这些值是字符串还是数组?
这是我到目前为止的代码:
<?php
$args = array( 'post_type' => 'ait-dir-item',
'meta_query' => array(
array(
'key' => 'location',
'value' => 'annapolis'
),
array(
'key' => 'item_tags',
'value' => 'non-marine'
)
),
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 300 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title('<h3 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h3>');
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
?>
感谢您的任何意见!
科里 -
答案 0 :(得分:0)
你是否有可能误认为自定义字段的标签 - “以逗号分隔的自定义字段item_tags”...听起来像是我的标签。对不起,如果我错了。
在这种情况下,它的一部分看起来像这样:
'tax_query' => array(
array(
'taxonomy' => 'item_tags',
'field' => 'slug',
'terms' => 'non-marine'
)
)
整件事情看起来像这样:
<?php
$args = array( 'post_type' => 'ait-dir-item',
'meta_query' => array(
array(
'key' => 'location',
'value' => 'annapolis'
),
),
'tax_query' => array(
array(
'taxonomy' => 'item_tags',
'field' => 'slug',
'terms' => 'non-marine'
)
)
'orderby' => 'title',
'order' => 'ASC', ... etc
如果您想要逗号分隔的标签,那么您应该真正使用custom taxonomies (codex here)!