Get Archive Page Id But Return Post Id In WordPress

Get Archive Page Id But Return Post Id In WordPress

目錄

Original Post

Get Archive Page Id But Return Post Id In WordPress


I had this annoying problem many times. When I wanted to get page id with get_the_ID in archive page, it returned an id of post. This is the best solution I found.

$url = 'http://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
$cur_post_id = url_to_postid( $url );

Related Posts

The Complete WordPress Customization Tutorial – Just Copy And Paste And Work

Content Protection by DMCA.com
A
Aron

Leave a Reply

Your email address will not be published. Required fields are marked *