Forums

Get the value of %postname%? (3 posts)

  1. tmpmb
    Member
    Posted 3 years ago #

    Hello,

    Is it possible to get the value of %postname%?

    Example:

    My permalink is setup link this:
    http://www.mysite.com/%postname%/

    I just want to grab that value of "/%postname%/" so if my post URL is this:
    http://www.mysite.com/my-first-post/

    I just want to grab the text "my-first-post".

    I know there's way to do this with some PHP coding but was wondering if there's already a built-in function on WordPress to do this.

    Any help will be greatly appreciated.

    Thanks

  2. Austin Matzko
    Member
    Posted 3 years ago #

    If you really just want my-first-post then use trim($_SERVER['REQUEST_URI']);

    If you want to find out more about that post, you can do something like the following:

    $post_id = url_to_postid($_SERVER['REQUEST_URI']);
    $post_data = get_post($post_id);
  3. Austin Matzko
    Member
    Posted 3 years ago #

    Whoops, I meant

    trim($_SERVER['REQUEST_URI'], '/');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.