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' );

Leave a Reply

Your email address will not be published. Required fields are marked *