我正在使用acf wordpress插件将一个布尔字段(featured_project)添加到自定义帖子(项目) .
我正在尝试对类别存档页面上的帖子进行排序,以显示在顶部显示的帖子和在底部显示非特色的帖子 .
有多个类别具有相同类型的帖子 .
我已经阅读了一些其他类似的问题,其中解决方案是使用'wp_query'或pre_get_posts,但我似乎无法让它工作 .
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( get_field('featured_project') ) { ?>
<article class='project featured' id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article">
<a href='<?php the_permalink(); ?>'>
<h3 class="h2"><?php the_title(); ?></h3>
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id() );
$width = 300;
$height = 200;
$crop = true;
$retina = false;
// Call the resizing function (returns an array)
$image = matthewruddy_image_resize( $url, $width, $height, $crop, $retina );
?>
<img src='<?php echo $image['url']; ?>'/ alt='<?php the_title(); ?>'>
</a>
<?php // the_post_thumbnail( 'projects-full', false ); ?>
<div class='excerpt'><?php the_excerpt(); ?></div>
</article>
<?php } else { ?>
是类别文件中代码的一部分 .
谢谢
更新:还没有找到解决方案,其他人可以加入吗?
1 回答
那么问题和解决方案不在这个代码块上...问题出在查询中,要解决此问题,您还应该查询元键
也许你还应该在查询上添加orderby(类似于
'orderby' => ' meta_value_num date'