Get page's parent's slug (post_name)
-
Hi all, I’ve been having some trouble getting the slug (post_name) of a page’s parent for some time now. I’ve figured out how to tell if a page is a child of another and all that, but all I can seem to get from that parent is its ID:
$post_obj = $wp_query->get_queried_object(); $post_name = $post_obj->post_name; $parent_name = $post->post_parent;
This just returns the ID of the parent page, and I really need to return the slug.
I have this function that does it elsewhere, but I can’t see to make it work for the parent:
function the_slug() { $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; return $slug; }
Say I have a main page called “Welcome” with the slug “welcome” and a sub-page under Welcome that is called “Hello” with the slug “hello.” I need to be able to use the value “welcome” when I’m on the page “Hello”
Any help someone could provide would be much appreciated.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Get page's parent's slug (post_name)’ is closed to new replies.