我想知道是否有人能帮我。我已经创建了一个自定义查询,以便在自定义单中检索。php检索具有相同自定义分类术语的帖子并显示它们。以下是查询:
<?php
$terms = wp_get_post_terms( $post->ID, \'customtaxonomy\' );
if($terms){
// post has course_type terms attached
$product_terms = array();
foreach ($terms as $term){
$product_terms[] = $term->slug;
}
$original_query = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( array(
\'post_type\' => \'customposttype\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'customtaxonomy\',
\'field\' => \'slug\',
\'terms\' => $customtaxonomy_terms, //the taxonomy terms I\'d like to dynamically query
\'posts_per_page\' => \'6\'
),
),
\'orderby\' => \'title\',
\'order\' => \'ASC\'
) );
if ( have_posts() ): ?>
//display what you want in loop here.
<?php endwhile; ?>
在该查询中,我希望有一个多条件语句,以便如果一个term=\'term1\'显示特定的图像。
<?php
foreach ( $terms as $term ) {
if($term->name == \'customtermincustomtaxonomy\') {
show image
}
}
?>
我知道我可以很容易地使用if/else语句,但这只允许我有2个条件。我知道我应该使用else-if语句,但我已经有一段时间没有使用php了,在格式化它时遇到了一些问题。我感谢你的帮助。