How to get the ID of a trashed post from functions.php
-
Hi friends,
I’m a noob, and I have a question: Is it possible to get the ID of trashed posts from functions.php when a visitor try to access it?I’m using this in my functions.php
function redirect_trashed_post(){ if( is_404() ){ global $wp_query, $wpdb, $post; $id = get_the_ID(); // <<--- trying to get this: the id of the current post // some other codes here... } } add_action('template_redirect', 'redirect_trashed_post');
I tried all the bellow methods but in vain:
(1) global $post; $post_id = $post->ID();
(2) global $wp_query; $post_id = $wp_query->get_queried_object_id();
(3) global $wp_query; $post_id = $wp_query->post->ID;
(4) $post_id = get_the_ID();
(5) $post_id = get_query_var(‘page_id’)Please help
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘How to get the ID of a trashed post from functions.php’ is closed to new replies.