PHP WordPress组合自定义帖子类型过滤
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP WordPress组合自定义帖子类型过滤相关的知识,希望对你有一定的参考价值。
<?php
// get portfolio
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'asc' );
$loop = new WP_Query( $args );
$port = array();
while ( $loop->have_posts() ) : $loop->the_post();
$idx = get_the_ID();
$year_completed = get_post_meta($idx, 'year_completed', true);
$website_addr = get_post_meta($idx, 'website_address', true);
$thumb = get_the_post_thumbnail($idx, 'thumbnail'); //250x200 - featured image
$title = get_the_title();
$excerpt = get_the_excerpt();
$content = get_the_content();
//get 'Solutions' terms
$terms = get_the_terms($idx, 'Solutions');
$terms_string = '';
//build up comma delimited string
foreach($terms as $t){
$terms_string .= $t->slug . ' ';
}
$port[] = array(
'id' => $idx,
'year_completed' => $year_completed,
'website' => $website_addr,
'thumb' => $thumb,
'title' => $title,
'content' => $content,
'excerpt' => $excerpt,
'terms' => $terms,
'terms_string' =>$terms_string, //classifications (comma delimited slugs)
'permalink' => get_permalink(),
);
endwhile;
$terms = get_terms('Solutions');
$filters = '<section id="options" class="clearfix">
<ul id="filters" class="option-set floated clearfix">
<li><a href="#filter" data-filter="*" class="selected">show all</a></li>';
foreach($terms as $t){
$filters .= '<li><a href="#filter" data-filter=".' . $t->slug . '">' . $t->name . '</a></li>';// $t->count
}
$filters .= '</ul></section>';
?>
<!-- add this inside entry-content -->
<?php echo $filters; ?>
<div id="portfolio">
<!-- isotope -->
<ul class="thumbnails isotope">
<?php foreach($port as $p){ ?>
<li class="span3 element <?php echo $p['terms_string']; ?>">
<div class="thumbnail">
<?php echo $p['thumb']; ?>
<div class="caption">
<h5><a href="<?php echo $p['permalink']; ?>"><?php echo $p['title']; ?></a></h5>
</div><!-- end caption -->
</div><!-- end thumbnail -->
</li>
<? } //end foreach ?>
</ul>
</div><!-- end #portfolio -->
以上是关于PHP WordPress组合自定义帖子类型过滤的主要内容,如果未能解决你的问题,请参考以下文章
按自定义日期范围输入过滤 wordpress 帖子
Wordpress - 如何通过其分类过滤添加的自定义帖子?
如何获取在 Wordpress 中按类别过滤的自定义帖子类型的永久链接?
WordPress > 从自定义帖子类型获取自定义分类
url中的wordpress自定义帖子类型类别slug
如何在wordpress rest api中过滤自定义帖子类型的自定义字段?