Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
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 '13 at 22:47
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.