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

Question

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.

0
Botond Vajna 8 months 2020-11-28T10:10:24-05:00 0 Answers 8 views 0

Leave an answer

Browse
Browse