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 building a search results template and want to display the parent section of the website for each result returned. so at the bottom of each search result excerpt it'd say "Found in [section] | Reacd More"

Something like: http://www.foxglovecovert.org.uk/search/results/search&keywords=local/

share|improve this question
How are you defining "section"? Category, parent page, template, something super cool that I don't even know exists? – Matthew Boynes Jan 28 '12 at 15:33
I'd like "blog", "gallery"(custom post format), "event"(custom post format), "about"(parent page) – Bent Jan 28 '12 at 19:59
up vote 0 down vote accepted

For your custom post types and your blog, you can use get_post_type(). For your About parent page, if the pages only go one level deep, you can check $post->post_parent to see if it's the about page. Otherwise, you can use get_post_ancestors() and check that array to see if your About page is in it!

share|improve this answer
Thanks. I think I can write the function I need from here. – Bent Jan 28 '12 at 20:48
function my_get_highest_parent( $id ) {
    $cat = get_category( $id );
    $parent = $cat->parent;

    if( $parent == 0 ) 
        return $id;
        my_get_highest_parent( $parent );

That will get you the highest level parent (the category with parent 0) based on the category-id you feed into it

share|improve this answer

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.