使用wordpress $ args获取多个类别

时间:2013-10-15 05:09:53

标签: php wordpress

我有这段代码:

<?php
global $post;
$args = array( 'numberposts' => 4, 'category' => 15 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>

问题在于我想要获取的不仅仅是15号类别。只需将它们添加到15旁边,如15,18或“15,18”不起作用。 有任何想法吗? 感谢

1 个答案:

答案 0 :(得分:1)

试试这个:它在我的项目中起作用。

<?php
global $post;
$args = array( 'numberposts' => 4, 'category' => '15,8');
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>

感谢。

相关问题