• I have tried using get_the_ID(), global $post; error_log(print_r($post->ID,true)), the_ID() and I cannot the post_ID of a page on load in WP. I have added:

        add_action( 'load-post.php', 'myFunc' );
        add_action( 'post.php', 'myFunc' );
        add_action( 'load-post-new.php', 'myFunc' );
        function myFunc(){...}

    How can I do this?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You need a later hook which fires once the query has been made. You could use “wp_head” action. It’s meant for outputting content in the <head> section, but you can just error log something without generating output. Get the ID from get_queried_object_id().

    This will work for single page requests, but you may get a term ID if the request is for a term archive, or null in some other archive request cases. If you want to further qualify what is logged, get the entire queried object with get_queried_object() and check its properties before logging.

Viewing 1 replies (of 1 total)
  • The topic ‘In WordPress, how can I get the error log to see a postID of a page on the load’ is closed to new replies.