Fatal error: Call to undefined function post_exists()

The files in wp-admin are only loaded when you’re in the admin area… when you’re looking at pages or posts those functions aren’t loaded. In that case you’d need to require the file first, so you’d want to do something like this in your function:

if ( ! is_admin() ) {
    require_once( ABSPATH . 'wp-admin/includes/post.php' );
}

The if ( ! is_admin() ) part is important because WordPress includes the file automatically when is_admin() is true so you only want to include it if is_admin() is false. Also make sure to include this snippet before you try to call the post_exists() function.

If that doesn’t work then try this:

if ( ! function_exists( 'post_exists' ) ) {
    require_once( ABSPATH . 'wp-admin/includes/post.php' );
}

Leave a Comment