• This is the most common tasks i have to do – how can i do it outside the loop (by passing the page ID)

    in other words:

    function get_parentSlug()
    {
    	global $post;
    	$parentID = $post->post_parent;
            get_post_slug($parentID);
    	return $parentSlug;
    }

    except why is there no function called simply “get_post_slug”?! or even “get_post_name”

    it boggles the mind

    jake

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jake.carvey

    (@jakecarvey)

    i can easily retireve the title – but that is nearly worthless:

    function get_parentSlug()
    {
    	global $post;
    	$parentSlug = get_the_title($post->post_parent);
    	return $parentSlug;
    }

    you might be able to do this via ‘get_post()’:

    function get_parentSlug()
    {
      global $post;
      $parentSlug = '';
        if($post->post_parent) {
          $post_parent = get_post($post->post_parent);
          $parentSlug = $post_parent->post_name;
        } ;
      return $parentSlug;
    }
    Thread Starter jake.carvey

    (@jakecarvey)

    excellent – that did the trick.

    I could have sworn I tried

    $post_parent->post_name;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to retrieve the Slug of a page outside the loop’ is closed to new replies.