Ecco un esempio di come è possibile farlo. Questo codice funzionerà se hai tutte le pagine che vuoi visualizzare sotto un genitore. In questo caso, stavo mettendo le pagine sotto la home page (p.post_parent = 2).
if ($post->post_type == 'page') {
$pages = $wpdb->get_results("SELECT p.ID, p.post_name, p.post_title, p.post_parent, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON pm.post_id=p.ID AND pm.meta_key='wp_menu_nav' LEFT JOIN $wpdb->posts AS P ON P.ID=p.post_parent WHERE p.post_parent = 2 AND p.post_type='page' AND p.post_status='publish' ORDER BY p.menu_order ASC");
if ($wpdb->num_rows > 0) {
foreach($pages as $page) {
//echo $page->ID . "<br>";
$args = array('numberposts' => 1, 'post_type'=> 'page', 'include' => $page->ID, 'post_status' => 'published');
$myposts = get_posts($args);
foreach($myposts as $mypost) {
setup_postdata($mypost);
echo the_content();
}
}
}
}
Se volevo applicare il modello che ho specificato in Wordpress su ciascuna di queste pagine? – Prusprus
Questo approccio è ora deprecato –
Sto cercando anche una risposta a questa domanda, ma 'get_page' è ora deprecato. Qualcuno può raccomandare un'alternativa, per favore? – mattnewbie