Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress查询类别名称和相关帖子_Wordpress_Custom Post Type_Custom Taxonomy - Fatal编程技术网

Wordpress查询类别名称和相关帖子

Wordpress查询类别名称和相关帖子,wordpress,custom-post-type,custom-taxonomy,Wordpress,Custom Post Type,Custom Taxonomy,我试图查询Wordpress自定义帖子和它们相关的类别。 查询操作异常,显示类别名称和所有海关公告,甚至与该类别无关(一直重复,直到显示所有类别名称为止) 示例图像: 我的查询代码: <div id="page-content-wrapper"> <div class="container-fluid"> <div class="lookbook-header"> <div class="wrap">

我试图查询Wordpress自定义帖子和它们相关的类别。 查询操作异常,显示类别名称和所有海关公告,甚至与该类别无关(一直重复,直到显示所有类别名称为止)

示例图像:

我的查询代码:

<div id="page-content-wrapper">
    <div class="container-fluid">
        <div class="lookbook-header">
            <div class="wrap">
                <p class="text-left">lookbook</p>
            </div>
        </div>

        <?php
        $taxonomy = 'lookbook_categories';
$terms = get_terms($taxonomy);

    $args=array(
     'taxonomy' => 'lookbook_categories'
    'post_type' => 'lookbook',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
        if ( $terms && !is_wp_error( $terms ) ) :
        foreach ( $terms as $term ) { ?>
            <div class="lookbook-category">
                <p class="text-center">
                    <?php echo $term->name; ?>
                </p>
            </div>
            <?php
if( $my_query->have_posts() ) {
        echo '';
        $count=0; 
while ($my_query->have_posts()) : $my_query->the_post();
if($count == 3) {?>
                <div class="row">
                    <?php }
    ?>
                        <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 no-padding">
                            <div class="lookbook-item">
                                <div class="hvrbox">
                                    <?php 
                                    $image = get_field('lookbook_image');
                                    if( !empty($image) ): ?> <img src="<?php echo $image['url']; ?>" alt="news" class="img-responsive" />
                                        <?php endif; ?>
                                            <div class="hvrbox-layer_top">
                                                <div class="hvrbox-text">
                                                    <div class="separator"></div>
                                                    <h3><?php the_title();?></h3>
                                                    <div class="separator"></div>
                                                    <p>
                                                        <?php the_field('excerpt');?>
                                                    </p>
                                                </div>
                                            </div>

                                </div>

                            </div>
                        </div>
                        <?php    
   $count++; 
        if($count == 3) echo '</div>';
        endwhile;
}
                                      }
                    endif;
wp_reset_query();
?>

                </div>
    </div>

lookbook

“alt=“news”class=“img响应”/>


我想显示类别名称+与类别相关的帖子(不是所有帖子反复显示)

您想将数组传递给
获取术语,如:

$terms = get_terms( array(
  'taxonomy' => 'lookbook_categories',
  'hide_empty' => false,
) );

您可以在此处阅读更多信息:

我已经在使用echo$term->name检索$terms的名称;我遇到的唯一问题是调用customposts的dublicated数组(与显示的类别无关,甚至不相关)@nate