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' );
}
Related Posts:
- Get post title by Alphabet
- How to change the case of all post titles to “Title Case”
- How to detect single.php (but not single-portfolio.php)?
- Function to execute when a post is moved to trash .
- Changing the post date and time with function
- Get current post id in functions.php
- Dynamically add id to heading tags
- Connection lost. Saving has been disabled… (Updating Posts/Pages)
- disable WP automatically inserted line breaks after an image
- Getting the post_id in wp_ajax function
- How to publish a post with empty title and empty content?
- delete post also attachments
- How to call function within a page/post, to dynamically generate content?
- Restrict users from editing post based on the age of the post
- How do I use element instead of tags in WordPress post content having webP support?
- Code to auto expire posts after 30 days
- List only child categories a post is in, of a specific parent category
- Keep a fluid max number of posts on site
- How to change post status from publish to draft using hook in wordpress?
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Custom colors for post rows based on post meta value
- How to add an admin function only to posts, not pages?
- Human Time Diff, change mins to minutes
- How to get new post URL?
- Force update all posts in custom post type, no content changes
- Custom wp_trim_words() function not trimming right
- Disable REST API for a user ROLE
- How to display post tags
- How to Display Post View Count
- Remove double space after a period
- Add confirmation popup on “Move to Trash”
- Allow role to delete posts but block him the wp-admin
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- Sql syntax error
- Delete Post From Front-End and attachment permanently
- Limit function to specific post category
- $post object is null
- Fatal error post.php help :(
- When paginating a Page with the tag, how can the 2nd and subsequent page styles be customised?
- Function to show random posts from a category
- ‘Invalid post type’ error when importing from one site to another
- How to change the page break URL from ../post/2 to …/post/page2/
- Hiding posts in a list from specified categories
- How can I list random authors from current post category?
- Disable single post page
- PHP Notice error (when on 404 page)
- Enabling post thumbnails for custom post type
- Run a function when post is deleted?
- Checking is user author of number of posts?
- Create cron job without a plugin?
- Getting a 404 error when clicking edit page
- Getting current post ID in functions.php
- How to rename “Publish” metabox title in post screen
- White Blank Page when Updating and Publishing Page/Post
- Action hook for new pending posts?
- Uppercase first sentence in every post
- Add icon/badge next to posttitle of specific category
- Ajax posts filter by date, comments, top views, top likes
- Prepend or add an Image to the content of a Post
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Why content_arr[‘extended’] removes paragraph tags?
- Load post attached images on a single page site with fancybox
- Exclude category from
- How do I get thumbnails?
- Run function after post is updated
- Authentication over CURL
- How to get posts from network blog
- When Author add new post change default status to pending
- fire action when post is being edited as well as saved?
- How to limit the number of results for all query_posts on mysite
- User driven content problems
- How can I create a menu items from meta box based on users input
- Getting rid of the blog page entirely
- How to use wp_editor(); in functions.php then retrieve content in the template
- List direct children of page
- How *not* to show the last post on the latest posts list
- Notify Author of the post if admin deletes his post and perform some function
- How do we display a certain category type on a page while hiding all others?
- save_post not working
- Display a custom field rating system in the front end
- wp trim function not working
- Insert Shortcode exactly at the end of the content
- Ajax calls in wordpress
- display last post modified date in genesis child themes
- What function does the loop of displaying posts?
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Show Next/Previous without Link
- Filters do not work when there are multiple (one works)
- Admin notice on wp_insert_post
- How to use shortcode to get the second to newest post?
- How to sort posts alphabetically based on a specific parent category
- Posts Page in WordPress loading bare HTML of my homepage
- Send post to remote wp site from post edit window with all data excerpt image
- Server 500 error when updating post using block editor
- WordPress current post functions inside loop doesn’t work anymore, are they incompatible with php 8.0?
- How can I strip a single tag from an email post
- Parameter for pagination posts_pagination
- Add function to single blog post pages only
- ERR_CONNECTION_RESET on post save or add media