Created
August 13, 2019 09:00
-
-
Save jaclyntan/855ccf013efa5c9da15b32e6f1d4a798 to your computer and use it in GitHub Desktop.
Get the ID from posts, pages, and archives in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( is_home() && ! in_the_loop() ) { | |
$ID = get_option('page_for_posts'); | |
} elseif ( is_post_type_archive()) { | |
$query = get_queried_object(); | |
$slug = $query->name; | |
$pageobj = get_page_by_title($slug); | |
$ID = $pageobj->ID; | |
} else { | |
$ID = get_the_ID(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment