如何从两个自定义帖子类型中获取所有帖子?

如何从两个自定义帖子类型中获取所有帖子?

问题描述:

如何使用WP_Query从两个自定义帖子类型(团队,工作)获取所有帖子?如何从两个自定义帖子类型中获取所有帖子?

这是我的代码:

$args = array(
    'post_type' => 'team', 
    'post_per_page'=>-1 
); 
$query = new WP_Query($args); 

您可以使用允许的类型的数组:

$args = array(
    'post_type' => array('team', 'work'), // Specify your types here 
    'posts_per_page' => -1 // Fixed typo here refer to postS 
); 
$query = new WP_Query($args); 

documentation包括关于如何使用WP_Query更多的例子。

+0

不工作柯克! – ganeshreddy

+0

@ganeshreddy它不起作用?你会得到什么结果? –

+0

只获取5篇文章,我想显示所有帖子。 – ganeshreddy

您可以在此处使用此代码进行查询。

$args = array(
    'post_type' => array('team','work'), 
    'post_per_page'=>-1 
); 
$query = new WP_Query($args); 

和更备查检查这个帖子

https://codex.wordpress.org/Class_Reference/WP_Query

$args = array(
    'post_type' => array('team', 'work'), // Specify your custom post types slug here" 
    'post_status' => 'publish', 
    'posts_per_page' => -1 
    'caller_get_posts' => -1 
); 
$query = null; 
$query = new WP_Query($args); 
+0

“caller_get_posts”是什么意思shital? – ganeshreddy