WordPress中的高级自定义字段查询
我试图在WordPress网站中列出所有帖子,而高级自定义字段值ispremium=>yes和post issticky。我的页面中有以下代码。它列出了所有帖子,但没有检查ispremium=>yes和issticky post,而是显示了所有帖子 我的代码出了什么问题WordPress中的高级自定义字段查询,wordpress,advanced-custom-fields,Wordpress,Advanced Custom Fields,我试图在WordPress网站中列出所有帖子,而高级自定义字段值ispremium=>yes和post issticky。我的页面中有以下代码。它列出了所有帖子,但没有检查ispremium=>yes和issticky post,而是显示了所有帖子 我的代码出了什么问题 <?php // args $args = array( 'numberposts' => -1,
<?php
// args
$args = array(
'numberposts' => -1,
'post_type' => 'post',
'meta_key' => 'ispremium',
'meta_value' => 'yes'
);
// query
$the_query = new WP_Query( $args and is_sticky());
?>
<?php if($the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<img src="<?php the_field('event_thumbnail'); ?>" />
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
-
试试这个:
$args = array(
'posts_per_page' => -1,
'post__in' => get_option( 'sticky_posts' ),
'post_type' => 'post',
'meta_key' => 'ispremium',
'meta_value' => 'yes',
'ignore_sticky_posts' => 1,
);
$the_query = new WP_Query( $args );
没有运气,它仍然显示所有的帖子。我在名为category-mycategory.php页面的自定义类别页面中有此代码。这有什么区别吗?我不知道。谢谢它的gr8。事实上,我在粘贴代码时犯了一些错误。问“这个代码有什么问题?”是这个网站的热门话题。请复习。你应该已经研究过你的问题,并且在发帖前自己编写代码。请阅读