invalid argument in foreach when trying to list custom post types in archive.php


I try to list pages of custom post type in archive.php, and I get this error message:

Invalid argument supplied for foreach()

$post_type = get_post_type( get_the_ID() );
$pages = get_pages(array( 'post_type' => $post_type ) );
    foreach ($pages as $page ) {
        echo '<div class = "prop-sidebar-section">';
        echo $page->post_title;
        echo '</div>';

the weird thing is, that with get_pages(array( 'post_type' => 'page'); is working, and if I use get_pages(array( 'post_type' => 'post') ); is not.

Botond Vajna 2 months 0 Answers 8 views 0

Leave an answer