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”
- Function to execute when a post is moved to trash .
- How to publish a post with empty title and empty content?
- How do I use element instead of tags in WordPress post content having webP support?
- Code to auto expire posts after 30 days
- Keep a fluid max number of posts on site
- 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
- Custom wp_trim_words() function not trimming right
- Remove double space after a period
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- Delete Post From Front-End and attachment permanently
- Limit function to specific post category
- 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
- Hiding posts in a list from specified categories
- PHP Notice error (when on 404 page)
- 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
- How to rename “Publish” metabox title in post screen
- 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
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Why content_arr[‘extended’] removes paragraph tags?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Show the content that is after the excerpt using child theme
- How to allow users to post only in certain category and hide elements from edit page?
- why are images not full size?
- Blank page when saving edits on post
- Display post x of y within category
- Force authors to Preview a post before publishing
- WordPress Automatic Filename Changer
- Order posts alphabetically: how to set order=asc in mysql query?
- What do these phpMyAdmin errors mean on my WordPress databaes?
- Post type no single page
- Adding a user’s ID behind the tag ref link address
- getting “Object of class WP_Post could not be converted to string” – when it is a string
- Isn’t the way posts are displayed very unefficient?
- How to check in functions.php if there is data in a WP_Query?
- restrict incrementation of post vies count when refreshing the page
- Defined function isn’t showed on page
- WordPress 302 Redirect to Random Product/Post/Page
- Getting Whitescreen when publishing a post [closed]
- Get post by tag
- Add code to a specific post’s content
- Related Posts function not working
- the_content() Not Grabbing All Content
- Related Posts: Changing Function For Posts Per Page
- Query function not executed between element [closed]
- Optimize CPT-function with a loop
- Have h2 tag not show up if there are no blog posts
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Making a wordpress page print friendly
- My post does not show up
- Set Default Post as Parent Child (Nested) Relation
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- Featured Images most often doesnt appear
- WordPress Post 403 Error Based on Slug
- How to put the author of the post in the comments?
- Check if almost 10 year old – working code is up to date
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- Function is printing twice – any suggestions?
- How to add a custom class attribute into code wrapper? [duplicate]
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- I want to change the WordPress comments file
- Excluding tag Link from html tags in Post content
- Save All Post Permalink From A Specific Category into a .txt file
- Changing a users posts to drafts upon role change
- How to Display Most View Post in the template file?
- Show post excerpt
- How do I apply a wordpress function to something with no ID inside an archive page?
- Show all posts from the tags without having to set all of them
- Show author bio box
- Check if user has avatar
- Trim excerpt to first paragraph
- All my posts don’t show, only the headline is displayed on the homepage
- Call image from post on index page?
- How to edit label_submit styling?
- How do I get thumbnails?
- Run function after post is updated
- 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
- Getting rid of the blog page entirely
- 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?
- What function does the loop of displaying posts?
- Admin notice on wp_insert_post
- How to sort posts alphabetically based on a specific parent category
- Posts Page in WordPress loading bare HTML of my homepage