I'm searching for posts this way

$args = array(
   'name' => $permalink,
   'post_type' => 'page',
   'post_status' => 'publish',
   'posts_per_page' => 1
$posts = get_posts( $args );

This works great for "page1" and "foo/page2" when I put "page1" and "page2" respectively in $permalink.

How can I craft a query to work for the case with where I want to search for "foo/page2"?

edit i want to get the post object so that I can retrieve some data from it.

  • You want to search for a post name on a particular page of the paginated results?
    – s_ha_dum
    Oct 26, 2013 at 19:00
  • @s_ha_dum not exactly. i just need to get a reference to the post object for it. Oct 26, 2013 at 22:45
  • 2
    I don't know what "get a reference to the post object" means in this context. What is the significance of the page component? Please try to make the question more cleat.
    – s_ha_dum
    Oct 26, 2013 at 22:47

1 Answer 1


If I understand well (and I'm not sure) probably you need only the get_page_by_path function:

$pagefoo = get_page_by_path('foo/page2');

$pagefoo variable contain post object for the page with slug 'page2' that is child of page with slug 'foo'.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.