根据术语打印每个自定义帖子的自定义ID

时间:2017-02-07 02:55:52

标签: php wordpress

function apiGetSupplies() {
    $supplies = array();
    if ( $this->f3->exists( 'supplies' ) ) {
        $supplies = $this->f3->get('supplies');
        $counter = $this->f3->get('counter');

        echo json_encode($supplies[$counter]);
        $counter++;
        $this->f3->set('counter',$counter);
    } else {
        //some sql call to define supplies 
        $this->f3->set('supplies',$supplies);
        $this->f3->set('counter',0);
    }
}

我想根据名称打印每个自定义帖子的名称和自定义ID。

  • 获取名称为<?php $loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1)); ?> <?php while ($loop->have_posts()) : $loop->the_post(); ?> <?php $i = 1; $terms = get_the_terms($post->ID, 'tagportfolio'); foreach ($terms as $term) { ?> <div class="col-md-3 col-sm-6 mix <?php echo $term->name . ' ' . $i; ?> "> <div class="pdf-thumb-box"> <a class="fancybox-media" href="<?php the_field('url'); ?>"> <div class="pdf-thumb-box-overlay"> <span> <?php the_title(); ?> </span> </div> <img class="img-responsive center-block" src="<?php the_post_thumbnail_url('medium'); ?>"> </a> </div> </div> <?php $i++; } ?> <?php endwhile; wp_reset_query(); ?>
  • 的所有自定义帖子
  • 获取每个学期
  • 对于每个术语,回显project
  • 的值
  • $i
  • 的增量值
  • 如果新字词重置值为$i$i

1 个答案:

答案 0 :(得分:0)

请试试这个:

<?php 
$terms = get_terms( array(
                    'taxonomy' => 'tagportfolio'
                ) );

foreach($terms as $term) {
    $i = 1;
    $loop = new WP_Query(array('post_type' => 'project', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1,'tax_query' => array( array('taxonomy' => 'tagportfolio', 'field' => 'id', 'terms' => $term->term_id)))); 
    while ($loop->have_posts()) : $loop->the_post();   ?>
            <div class="col-md-3 col-sm-6 mix <?php echo $term->name . ' ' . $i; ?> ">
                <div class="pdf-thumb-box">  
                    <a class="fancybox-media" href="<?php the_field('url'); ?>">
                        <div class="pdf-thumb-box-overlay">
                            <span>
                                <?php the_title(); ?>
                            </span>
                        </div>
                        <img class="img-responsive center-block" src="<?php the_post_thumbnail_url('medium'); ?>">
                    </a>
                </div>
            </div>
            <?php $i++; ?>
        <?php
    endwhile;
    wp_reset_query();
}
?>