WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
You want to search for a post name on a particular page of the paginated results? – s_ha_dum Oct 26 '13 at 19:00
@s_ha_dum not exactly. i just need to get a reference to the post object for it. – Daniel A. White Oct 26 '13 at 22:45
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 '13 at 22:47
up vote 1 down vote accepted

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'.

share|improve this answer
thanks this is exactly what i needed. – Daniel A. White Oct 27 '13 at 1:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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