我有循环输出最后3个帖子:
<?php
$args = array( 'numberposts' => 3 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
/////////insert smth
<?php endforeach; ?>
我需要确保帖子类别等于“vakancy”,我是否可以只过滤此类别的帖子,或者我必须使用(如果!=)?
答案 0 :(得分:1)
当然很简单:https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
<?php
$args = array( 'numberposts' => 3, 'category_name' => 'vakancy' );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
/////////insert smth
<?php endforeach; ?>