在Wordpress中,我试图获取多个类别中的所有帖子。继承我的代码:
<?php
// Get categories
$menu = 'left-column-menu';
$cat_args = array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'nav_menu_item',
'post_status' => 'publish',
'output' => ARRAY_A,
'output_key' => 'menu_order',
'nopaging' => true,
'update_post_term_cache' => false );
$cat_items = wp_get_nav_menu_items( $menu, $cat_args );
// Get categories posts
$args = array(
'posts_per_page' => '',
'offset' => 0,
'category' => $cat_items->ID,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
$posts = get_posts($args);
print_r($posts);
?>
第一部分是从菜单中获取类别,这很好。但它只获得前5个帖子。我只是想知道为什么会这样?
答案 0 :(得分:0)
变化:
// Get categories posts
$args = array(
'posts_per_page' => '',
要:
// Get categories posts
$args = array(
'posts_per_page' => -1,