Trying to figure out why this won't work for me. I'm simply trying to run a loop of all posts and pages, and tag them as post and page in a array. But the is_single()
conditional is not working, all posts show up as pages. And if I remove the is_page()
it'll just give me null
$data = array();
$args = array(
'posts_per_page' => '-1',
'post_type' => array('post', 'page'),
'orderby' => 'menu_order',
'order' => 'ASC',
);
$loop = new WP_Query($args);
if( $loop->have_posts() ):
while( $loop->have_posts() ): $loop->the_post();
$id = $loop->post->ID;
if(is_single()) {
$type = 'article';
} elseif(is_page()) {
$type = 'page';
}
$data[$id] = array(
'uri' => $loop->post->post_name,
'title' => apply_filters( 'the_title', $loop->post->post_title ),
'type' => $type,
'entry' => apply_filters( 'the_content', $loop->post->post_content ),
);
endwhile;
endif;
wp_reset_postdata();