smashp
smashp

Reputation: 163

how to get real link from wordpress api

im using wordpress permalink "post name" %postname%/

so my page link looks like this :

http://designonsky.com/sample-page/

post name permalink

but i want to get the real link :

http://designonsky.com/?page_id=2

real link

im asking if there's a wordpress function ( or php function ) to do that .

no .htaccess please .

sorry for my english

thanks advanced!

Upvotes: 0

Views: 254

Answers (2)

RRikesh
RRikesh

Reputation: 14381

Not tested, you could use something like:

if( is_page() ){
  echo home_url() . '/?pageid=' . get_the_ID();
}
elseif( is_single() ){
  echo home_url() . '/?p=' . get_the_ID();
}
elseif ( is_category() ){
  echo home_url() . '/?cat=' . get_the_ID();
}

Upvotes: 1

emeraldjava
emeraldjava

Reputation: 11190

You can use get_the_ID method to return the current page or post id.

Upvotes: 0

Related Questions