Tribe__Main::post_id_helper( null|int|WP_Post $candidate = null )

Get the Post ID from a passed integer, a passed WP_Post object, or the current post.

Helper function for getting Post ID. Accepts null or a Post ID. If attempting to detect $post object and it is not found, returns false to avoid a PHP Notice.


Parameters

$candidate

(null|int|WP_Post) (Optional) Post ID or object, null to get the ID of the global post object.

Default value: null


Top ↑

Return

(int|false) The ID of the passed or global post, false if the passes object is not a post or the global post is not set.


Top ↑

Source

File: src/Tribe/Main.php

	public static function post_id_helper( $post = null ) {
		if ( ! is_null( $post ) && is_numeric( $post ) > 0 ) {
			return (int) $post;
		} elseif ( is_object( $post ) && ! empty( $post->ID ) ) {
			return (int) $post->ID;
		} else {
			if ( ! empty( $GLOBALS['post'] ) && $GLOBALS['post'] instanceof WP_Post ) {
				return get_the_ID();
			} else {
				return false;
			}
		}
	}