나는 그들의 올해와 meta_key에 의해 게시물을 표시하고자하는 포트폴리오 사이트의 index.php를 구축하고 있습니다. 메타 키는 "추천 프로젝트"옵션으로 사용됩니다.년 및 메타 키 반환 빈 게시물
처음에는 다른 프로젝트 연도를 용어로 사용하여 사용자 지정 분류법을 작성하고 foreach를 사용하여 연도 옆에 게시물을 채 웁니다. 용어가 이미 무언가가 여전히 연도를 출력하기 때문에 (!?) 용어를 작동하지 않습니다 IT와 메타 값으로 taged되는 값을 가지고 있기 때문에
<?php $years = get_terms('year', 'orderby=name&order=desc&hide_empty=1'); ?>
<?php foreach($years as $year) : ?>
<div class="front-index"><p><?php echo $year->name; ?></p></div>
<?php
$year_query = array(
'post_type' => 'works',
'meta_key' => 'post_h2_mask',
'meta_value' => '1',
'taxonomy' => 'year',
'term' => $year->slug);
$year_posts = new WP_Query ($year_query);
?>
<?php while ($year_posts->have_posts()) : $year_posts->the_post(); ?>
…
이는 경우에도, 작동하지 않았다 게시물에 meta_value가 없습니다.
은 ... 은 그래서 솔루션은 올해 게시물을 채우기 위해 워드 프레스 자신의 "게시"날짜를 사용할 수있을 것으로 생각했다. 그리고 이것을 위해 나는 mysql 스 니펫을 발견하고 이것을 약간 돌아 보았습니다.<?php
$years = $wpdb->get_col("
SELECT DISTINCT YEAR(post_date)
FROM $wpdb->posts
WHERE post_status = 'publish'
AND post_type = 'works'
ORDER BY post_date DESC");
?>
<?php foreach($years as $year) : ?>
<div class="front-index"><p><?php echo $year; ?></p></div>
<?php
$year_query = array(
'post_type' => 'works',
'meta_key' => 'post_h2_mask',
'meta_value' => '1',
'year' => $year
);
$year_posts = new WP_Query ($year_query);
?>
<?php while ($year_posts->have_posts()) : $year_posts->the_post(); ?>
<?php
$attachments = new Attachments('attachments');
if($attachments->exist()) :
?>
<div class="front-work">
<div class="wraptocenter">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_post_thumbnail('front-thumbnail'); ?>
<p><?php the_title(); ?><br /><span class="image-count">
<?php
$project_cats = get_the_terms($post->ID, 'medium');
$project_cats = array_values($project_cats);
for($cat_count=0; $cat_count<count($project_cats); $cat_count++) {
echo '<span>'.$project_cats[$cat_count]->name.'</span>';
if ($cat_count<count($project_cats)-1){
echo ', ';
}
}
?>,
<span><?php echo $attachments->total(); ?> images</span></span></p>
</a>
</div>
</div>
<?php endif; endwhile; ?>
<?php endforeach ?>
이것은 div에서 몇 년이 걸리지 만 링크가있는 게시물은 단 1 개이며 2006 년부터 하나뿐입니다!
meta_key를 사용하여 연간 소속 옆에 게시물을 얻는 방법은 무엇입니까?