Skip to content

Instantly share code, notes, and snippets.

@mlbd
Last active July 21, 2018 13:13
Show Gist options
  • Save mlbd/58f62befc7e61fdae291ff48bf33103d to your computer and use it in GitHub Desktop.
Save mlbd/58f62befc7e61fdae291ff48bf33103d to your computer and use it in GitHub Desktop.
/**
* Custom excerpt
*
* @since 1.0
*
* @uses get_queried_object()
*
* @see get_the_ID()
*
* @return int
*/
if ( !function_exists( 'get_the_real_ID' ) ) {
function get_the_real_ID() {
if (in_the_loop()) {
$post_id = get_the_ID();
} else {
if ( is_front_page() && !is_home() ) {
$frontpage_id = get_option( 'page_on_front' );
$post_id = $frontpage_id;
} elseif ( !is_front_page() && is_home() ) {
$page_for_posts = get_option( 'page_for_posts' );
$post_id = $page_for_posts;
} else {
global $wp_query;
$page_object = $wp_query->get_queried_object();
if ( is_page() || is_singular() ) {
$post_id = $wp_query->get_queried_object_id();
} else {
$post_id = 0;
}
}
}
return $post_id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment