Find the page or post for a given permalink

25 November 2010, Comments: 0

Today I was wondering how I can get the page object, including the page_id from WordPress.

After some investigation I figured out, that the permalink is written in the page_name in each posts wp_posts table.

Then figured out, that the WordPress function get_page_by_path($page_path, $output = OBJECT, $post_type = ‘page’) could solve my problem.

So, then I just called this method with the given permalink as path and it worked.

So for example, have permalink of our website and we want to have that page object of the about – page:

// define the permalink path
$permalink = 'about';

// get the page object from the permalink
$page = get_page_by_path($permalink);

This was performed on a WordPress 3.0.1.

Leave a Reply