You can hook into before_delete_post
and redirect before completing the deletion.
add_action('before_delete_post', function($post_id) {
// Get custom field
$field = get_post_meta( $post_id, 'key', 'true');
// Redirect if field is empty
if (!$field) {
wp_redirect(admin_url('edit.php'));
exit();
}
}, 1);
Related Posts:
- Add a checkbox to post screen that adds a class to the title
- Prevent duplicate posts in wp_insert_post using custom fields
- Add custom fields to post programmatically
- Add a custom meta box in the post options that loads some html code in the header
- Customize rel=canonical tag for single blog post
- Edit multiple custom post types while saving a new or edited post
- if in category but only with post meta
- Adding an option to post editor to show a site disclaimer or message
- First Custom Post Custom Fields Empty After New Custom Post
- How to Do Custom Fields to Output a Definition List
- Attach pdf file to custom post type
- I am trying to create a simple frontend form for posting
- HTML code in Custom field
- Delete Post Link to delete post, its meta and attachments
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Add custom field to category of custom post type
- Change post format using custom field
- How can I make existing custom fields easier to edit/add in my theme?
- What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
- How to get Advanced Custom Field Value According using POST ID? [closed]
- user contributed content as custom post types
- Remove custom posts that match taxonomy value
- Custom Theme Want To Remove One Category From All Displays
- Filter Posts By Tag
- Post Type Label Name
- wp_query ‘s’ parameter does not work with custom post type
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Understanding and using metaboxes in posts
- Blog Posts in Custom Menu
- How to display data in archive page?
- Set terms in a custom post
- Move first half of posts to one parent page, second half to the other page
- Custom Post Type – Category Rewrite – Remove Rewrite from Sitemap
- CPT archive redirects to single post
- Prevent Delete Attachment by URL or When Submit
- Turn On Comments On Custom Post Types in Directory Theme
- Responsive images with custom image size
- Duplicate Custom Post Type and Taxonomy Slug
- Take a received feedback item, turn it into a post
- Calling Different Custom Post Timestamps in a table
- How to allow visitors to filter posts by multiple taxonomies
- How to include my own css in post
- a little direction on custom post type
- Get post meta retrieving wrong value
- How safe is it to delete old posts edits to save database space?
- Is codex right on deleting post?
- Create a custom posts page
- How to get different Related Posts
- Output Post with ACF Fields into other Post
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- register_post_type permalink
- Custom Post Limit for homepage only without plugin?
- Inserting an example of the last 3 post on to the homepage
- Static pages not working
- Get a term each custom post type
- Post titles and thumbnails as links to custom post types?
- Adding a custom post type meta field to rss
- Help with listing current users submitted custom post type in template file
- Deleting old posts
- How To Use Custom Tax of a Post Type
- Display content between two dates?
- How to save template data into wp_post table (post_content column)
- Override WordPress core post-template.php block template
- Custom Fields – How to get the list of a specific active widget each time it rendered
- get posts, run a custom query, and join the results
- search form for custom fields
- Search results for ACF data
- Saving canvas generated image when saving post causes 404 error
- Some custom post types did not return an object
- Display Post from Custom Post Type with Shortcode
- Redirect to custom post if custom archive page has just one result?
- Modified core/image rendering not showing in posts – only on pages
- Not display an image of category of custom post
- Show post count in custom taxonomy page
- How do you update post date (year only) in a separate custom field?
- Post relationships/nesting
- Is it possible to make a custom post that adds multiple pages?
- Displaying dynamic content (blog posts/portfolio) on a static homepage and keep the blog post styles
- Multiple Custom Post Type loop logic
- WordPress search for specific Post Type
- How can you control what a user is allowed to post in the backend?
- How to show content of specific item on the same page?
- Custom URL Structure for posts with subcategories
- How to show the posts list into a static page? Problems to use the loop into a static page
- 404 for some custom taxonomy not ALL taxonomy
- How to custom sort-out editing-panel fields?
- How can I create a menu items from meta box based on users input
- Home page: using custom fields for posts and pages
- Add default content to post (for specific category)
- Setting default category for display
- How would I attach media/images to a post based on a ID stored in a each post’s custom field
- WordPress strips some attributes for author posts
- Display one post randomly from category on home page
- Deleting first four characters from all Post Titles
- Deleling wordpress posts permanently still have IDs
- Post’s arent displaying
- Can I get custom post items in select box (dropdown)
- How to have 2 posting pages on a blog
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- Image inside the content is replaced with featured image from my older post