Support » Fixing WordPress » Post ID outside of loop, after custom WP_query, in footer

  • So I have this function tht I want to pass a page/post ID to. Let’s say it’s this function:

    function log_the_id ($id) {
    error_log("The ID is: " . $id);

    So the function basically just puts something in the debug.log file, located in wp-content. Now when I call this function on a normal page it works just fine:


    However, when I call this function after a custom loop, it does not work. That makes sense, because the $post variable is now the post from the custom WP_query, and not that of the page loop.

    The strange thing is though, that when I call this function above the standard page loop and above the custom WP_query, it logs both the ID of the custom loop, and that of the post(s) in the WP_Query.

    So for instance, lets say the page in which the function is called has an ID of 10, and the post in the custom WP_Query has an ID of 20, then the debug.log shows:

    The ID is: 10
    The ID is: 20

    So the function is called twice, and all I need is the ID 10.

    Thnx for the help!

  • The topic ‘Post ID outside of loop, after custom WP_query, in footer’ is closed to new replies.