I try to push each data from the Wordpress loop into array:
<?php
$array = array();
$args = -1;
$posts = get_posts($args);
foreach ($posts as $post){
array_push( $array, array(
"title" => get_the_title(),
//capire perchè non stampa il contenuto
"cont" => get_the_content()
));
}
print_r($array);
?>
The problem was that I want to have final data into the multidimensional array but I have only the title value but NOT the content.
Your loop is fine. To access the content get_the_content()
you need to use setup_postdata
. It sets up the global post data for template tags.
foreach ($posts as $post){
setup_postdata($post);
...
}