At the beginning of wp_insert_post
, the function that saves/updates a post, there is a filter called wp_insert_post_empty_content
. By default this filter checks whether the title, editor, and excerpt fields are all empty, in which case the save process will be halted.
However, since all the fields to be saved are passed to this filter, you can expand this filter to include any other test to determine whether the post should be considered empty. It would be something like this:
add_filter ('wp_insert_post_empty_content','wpse312975_check_unique_url',10,2);
function wpse312975_check_unique_url ($maybe_empty, $postarr) {
// extract custom field from $postarr, check uniqueness
if ($unique) return false else return true;
}
Note: the function must return ‘true’ to halt the saving process.
If the custom field is not unique you may also want to echo a warning.
Related Posts:
- Using custom fields in a filter hook
- Registration and Profile custom field
- change attachment custom field onChange event
- Set new url from custom post field
- Passing a parameter to filter and action functions
- Difference Between Filter and Action Hooks?
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- How to know what functions are hooked to an action/filter?
- Get a list of all registered actions
- How can I edit post data before it is saved?
- Trouble understanding apply_filters()
- Is there a way to set default custom fields when creating a post?
- How many filter/action hooks are healthy?
- Earliest hook to reliably get $post/$posts
- Add subtitle to Woocommerce product title
- Filter WP_Query for posts having a certain meta-value
- What does (10, 2) mean when used with add_filter
- How to only hook on Single.php after content?
- Valid characters for actions, hooks and filters
- How to check if a hook is hooked or not?
- Implementing advanced add_* function wrappers
- Apply the_content filter to a custom field with multiple values
- Pass all custom fields through the same filter on post load?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How do I Make a Theme “plugin-ready”?
- How to make post and comment count unclickable with dashboard_glance_items hook
- Hook into admin post list page
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- Filter results with custom field values and dropdown
- getEntityRecord without knowing the post type
- Archive sorting functions by custom fields (front-end)
- Get updated meta data after save_post hook
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Check before publishing, if already exist post with current custom field value
- About Hooks and Filters
- How to debug removal of rewrite rule flushing?
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Please explain me what the do_action does
- Change content before writing to database
- post meta data clearing on autosave
- Is it possible to create an action hook using do_action() within add_action()?
- WordPress Search Custom Meta Field Only
- Display info from custom fields in all images’ HTML
- Use external link in the add sub menu
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- Update meta values with AJAX
- Add an advert every nth Paragraph
- Too many actions/filters!
- do_action and hook methods
- How to get list of all hooks of current theme / plugin?
- Find variables available at a given hook
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- How to filter a dd/mm/yyyy date from a custom field in a query
- Define a function outside a class and call the function using action or filter hook
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- Conditionally call add_action depending on post_type?
- Remove “Get Shortlink” button in admin of custom post type
- Woocommerce – Hide a Column in Cart Table
- Is there a Woocommerce hook that fires when applying a coupon but before checking if it’s valid?
- What is the action hook for an order that fails on frontend checkout in WooCommerce?
- Is it possible to track down Actions and Filters?
- When to use actions and when to use filters
- Force hide custom field metaboxes
- Saving custom profile fields
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- How can i do something after head like adding a hook for after head but before post
- Same Conditionals Not Working on Two Different Hooks
- How to call a function or method that is Namespaced using another plugin
- add filter login_redirect does not contain original requested redirect
- get_header and hook avoid normal call
- Accepted arguments value in hook functions
- how to determine how many and what kind of arguments are passed to hooks
- Can the wp_filter object hold multiple values with the same key
- Update posts after populating ACF field value [closed]
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- Which action hook to use for function?
- How to validate custom field on lost password form before the user id field?
- Namespaced action and filter tags
- apply_filters/do_action tag characters limit
- How to update a meta field of type array in Gutenberg
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- Filter taxonomy admin pagination
- Modify a function without editing template
- Insert term when page is published – avoid duplicates after edits
- add_action and remove_action if custom field exists
- Capture post content before page renders
- filtering custom post types via meta data drop down
- global function to apply filter to custom field
- How to order posts by one custom field and filter them by another one?
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- How to remove action with slashes and arrows?
- Send email with custom fields after new draft is saved or new post published
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Get Time Taken By Each Action Hook in WordPress
- Changing WordPress core without hacking core
- Filter multiple custom fields Values with Check boxes
- How to get categories with posts by custom field value?
- Comment search plugin