I use this code to import posts from an external script. https://gist.github.com/davejamesmiller/bc9d443da989c6692441

This works but I need to check if a post exits. So I want to use post_exists().

if(post_exists("test") > 0) {

I got this error:

Fatal error: Uncaught Error: Call to undefined function post_exists() 

Is it possible to check in an external script for posts?


post_exists() doesn't exist because you forgot to include the file where the function is declared. Looking to https://developer.wordpress.org/reference/functions/post_exists/#source you can see that it's declared in wp-admin/includes/post.php

Add this to your existing code juste after the require of taxonomy.

require_once ABSPATH . '/wp-admin/includes/post.php';

The best way to achieve what you want is to use wp-api in my opinion !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.