get_all_page_ids() WordPress Function

The get_all_page_ids() function is a simple way to get an array of all the post IDs for all the pages on your site. This can be useful for a number of different things, such as making sure that a certain piece of code is only run on pages, or getting a list of all the pages in a particular order.

get_all_page_ids() #

Get a list of page IDs.


Return

(string[]) List of page IDs as strings.


Top ↑

Source

File: wp-includes/post.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More