get_all_page_ids()WP 2.0.0

Get a list of page IDs.

No Hooks.

Return

String[]. List of page IDs as strings.

Usage

get_all_page_ids();

Examples

0

#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
)
0

#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. $wpdb WordPress database abstraction object.

Changelog

Since 2.0.0 Introduced.

get_all_page_ids() code WP 6.6.2

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;
}