Php ACF Wordpress&;排序类别存档页
我正在使用acf wordpress插件向自定义帖子(项目)添加一个布尔字段(特色项目) 我试图对分类档案页面上的帖子进行排序,以显示顶部的特色帖子和底部的非特色帖子 同一类型的帖子有多个类别 我读过一些类似的问题,解决方法是使用“wp_query”或pre_get_posts,但我似乎无法让它工作Php ACF Wordpress&;排序类别存档页,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我正在使用acf wordpress插件向自定义帖子(项目)添加一个布尔字段(特色项目) 我试图对分类档案页面上的帖子进行排序,以显示顶部的特色帖子和底部的非特色帖子 同一类型的帖子有多个类别 我读过一些类似的问题,解决方法是使用“wp_query”或pre_get_posts,但我似乎无法让它工作 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if ( get_field('
<?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 { ?>
是类别文件中代码的一部分
谢谢
更新:仍然没有找到解决方案,其他人可以插话吗 问题和解决方案不在这段代码上。。。问题在查询中, 要解决此问题,还应查询元密钥
<?php
$args = array_merge( $query,
array(
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'featured_project',
'value' => 1, // test if your value is a number or string
//'type' => 'BINARY', //Maybe you should cast the meta value
'compare' => '='
),
),
)
);
$custom_query = new WP_Query( $args ); ?>
?
<?php if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post(); ?>
<?php if ( get_field('featured_project') ) { ?>
?
也许您还应该在查询中添加orderby(类似于
'orderby'=>'meta\u value\u num date'
您是否尝试查看get\u字段的值('featured\u project'))?是的,但我看到的唯一获取它的方法是在循环内,或者在循环外传递帖子id。是的,但是你确定你的如果语句正在工作就是我说的,你想让get_字段…返回true或1,它会给你这个吗?啊,好的,对不起,是的,我为每个帖子获取预期的1或0。好的,那么你有东西打印了吗,只是顺序不对?谢谢,但我得到了一个“警告:array_merge():参数#1不是数组”,它与$args=array_merge($query)相关,当我删除$query时它会消失,但是帖子会消失。转储$query时会得到什么?echo”“;var_dump($query,“Hello”);echo”;die;
它只输出为null,$query=to应该是什么?--您能提供您的代码吗?请阅读以下内容: