get_all_page_ids()
Gets the ID of all permanent pages of type page.
No Hooks.
Returns
String[].
Usage
$ids_array = get_all_page_ids();
Examples
#1 Demo example:
$ids_array = get_all_page_ids(); print_r( $ids_array );
Display something like:
Array ( [0] => 19 [1] => 4 [2] => 7 [3] => 25 [4] => 155 [5] => 247 [6] => 280 [7] => 365 [8] => 760 [9] => 1544 [10] => 2005 )
#2 Display all pages titles
$page_ids = get_all_page_ids();
echo '<h2>My Page List :</h2>';
foreach( $page_ids as $page ){
echo sprintf( '<h3>%s</h3>', get_the_title( $page ) );
}
Notes
- Global. wpdb.
$wpdbWordPress database abstraction object.
Changelog
| Since 2.0.0 | Introduced. |
get_all_page_ids() get all page ids code WP 7.0
function get_all_page_ids() {
global $wpdb;
$page_ids = wp_cache_get( 'all_page_ids', 'posts' );
if ( ! is_array( $page_ids ) ) {
$page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" );
wp_cache_add( 'all_page_ids', $page_ids, 'posts' );
}
return $page_ids;
}