get_page_by_title

Definition:
function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) {}

Retrieve a page given its title.

Parameters

  • string $page_title: Page title
  • string $output: Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
  • string $post_type: Optional. Post type. Default page.

Source code

function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) {

	global $wpdb;

	$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) );

	if ( $page )

		return get_page($page, $output);



	return null;

}

1532

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: