[英]How can I display projects that only use a tag of my choosing. Currently all projects are being fetched
我正在嘗試修改一個使用一些循環和if語句來基於那里的標簽獲取項目的projects.php文件。 我需要將以下代碼修改為僅獲取帶有new標簽的項目。 當前,所有項目都正在獲取和顯示。
任何幫助都會很棒。 參見附帶的代碼。
謝謝
<div id="projects" class="clearfix">
<?php $page_skills = get_post_meta($post->ID, "_ttrust_page_skills", true); ?>
<?php $skill_slugs = ""; $skills = explode(",", $page_skills); ?>
<?php if (sizeof($skills) >= 1) : // if there is more than one skill, show the filter nav?>
<?php $skill = $skills[0]; ?>
<?php $s = get_term_by( 'name', trim(htmlentities($skill)), 'skill'); ?>
<?php if($s) { $skill_slugs = $s->slug; } ?><?php endif;
$temp_post = $post;
$args = array(
'ignore_sticky_posts' => 1,
'posts_per_page' => 200,
'post_type' => 'project',
'skill' => $skill_slugs
);
$projects = new WP_Query( $args );
endif; ?>
<div class="wrap">
<div class="thumbs masonry">
<?php while ($projects->have_posts()) : $projects->the_post(); ?>
<?php
global $p;
$p = "";
$skills = get_the_terms( $post->ID, 'skill');
if ($skills) {
foreach ($skills as $skill) {
$p .= $skill->slug . " ";
}
}
?>
<?php get_template_part( 'part-project-thumb'); ?>
<?php endwhile; ?>
<?php $post = $temp_post; ?>
</div>
</div>
您只需要在$ args數組中添加一個字段:
$args = array(
'ignore_sticky_posts' => 1,
'posts_per_page' => 200,
'post_type' => 'project',
'skill' => $skill_slugs,
'tag' => 'new' // add this for the tag
);
$projects = new WP_Query( $args );
讓我知道它是否有效:D
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.