Here is the code of wordpress custom plugin.?
$pages = get_pages();
foreach ($pages as $page) {
$pagee=$page->post_title;
}
echo $pagee; <---- I want here all pages name in variable.
please suggest how can i do it.
You have just to append your variable like this
$pages = get_pages();
$pagee = array();
foreach ($pages as $page) {
$pagee[] = $page->post_title;
}
echo implode(",",$pagee);
You can do it this way:
// To save all pages
$allpages = array();
$pages = get_pages();
foreach ($pages as $page) {
// function array_push to insert the data at the end of the array
array_push($allpages, $page->post_title);
}
// Show the array
print_r($allpages);
or this:
$i = 0; // counter
$allpages = array(); // array to save all pages
$pages = get_pages();
foreach ($pages as $page) {
$allpages[$i] = $page->post_title; // save the value in the array by an index
$i++; // increment the counter
}
print_r($allpages);
Try declaring an array to store all values of $pagee while the loop runs:
$pages = get_pages();
$pagee = [];
foreach ($pages as $page) {
$pagee[]=$page->post_title;
}
print_r($pagee); // print the array of all cycles
So, $pagee will contain all the values of $pagee for each cycle in the loop.
$pageean array and add to it each foreach loop?$pagee[]=$page->post_title;