## posts – Why is a wp function used in current PHP namespace’s callback not resolved to global scope?

Question

Imagine the following script:

<?php
namespace MySpace;

class MyClass {

public static function execute() {
// Do something
post_exists(1,'','','my_post_type');
}

}
?>


I’m now calling this function at the top of the page template, before any HTML. The problem I get is that wp resolves the post_exists function to the namespace instead of falling back to the global scope, where wp functions are usually recognized in such cases.

So I actually get a PHP error saying Call to undefined function MySpace\post_exists(), why is that so? Is, at that moment, before the document head, the wp core not initiated, or something similar? Never experienced this bug so far…

0
8 months 2022-04-04T19:08:55-05:00 0 Answers 0 views 0