Ok, after a little playtime, here is the answer:
add_action('save_post', 'ocp_jobs_save_details');
function ocp_jobs_save_details(){
global $post;
$genref = sanitize_title( dechex( time() ) );
if ( $post->post_type == 'job' ) {
if ( $_POST['ocp_jobs_ref'] ) { $jobs_args = array( 'ID' => $post->ID, 'post_name' => strtolower( sanitize_title( $_POST['ocp_jobs_ref'] ) ) ); $myref = strtoupper( $_POST['ocp_jobs_ref'] ); }
else{ $jobs_args = array( 'ID' => $post->ID, 'post_name' => strtolower( $genref ) ); $myref = strtoupper( $genref ); }
if ( ! wp_is_post_revision( $post->ID ) ){
remove_action('save_post', 'ocp_jobs_save_details');
wp_update_post( $jobs_args );
add_action('save_post', 'ocp_jobs_save_details');
}
}
update_post_meta($post->ID, "ocp_jobs_ref", $myref);
// Other update_post_meta functions
}
The wp_insert_post_data
filter isn’t needed at all. It probably isn’t pretty or elegant, but it works.
Related Posts:
- Prevent post from being published if custom fields not filled
- Using Custom Fields in Custom Post Type URL
- Trying to save custom post type from frontend partially working
- Frontend posting – everything saves other than checkboxes?
- Is it possible to create a post using a metabox?
- Confusion regarding Nonce & using it in Custom Columns for Saving Checkbox Value to Post Meta
- Custom Post Meta from custom metaboxes is randomly being deleted
- Custom Post Type Metadata Not Saving
- What do the numbers mean at the end of add_action(‘save_post’)…?
- How to use a specific custom field in a custom post type as slug
- How to prevent meta data from being edited in a post?
- Custom Post Type Meta Box Text Input Field Won’t Save When Blank
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- wp_insert_post deleting previous post custom meta
- Is this the correct way to add post-slug input field?
- Advanced search form with filters for custom taxonomies and custom fields
- Help Creating a Slideshow Custom Post Type with Custom Meta Boxes?
- Custom Post type & Taxonomy URL structure
- Search multiple custom fields by using meta_query
- Custom Post Type – Taxonomy Dropdown Menu?
- How do I programmatically add items of content to a custom post type?
- How do I implement custom fields without using any plugins?
- How I check if the same post slug has not been used before publishing?
- How to sort a table of custom posts by column containing custom field
- order by meta_value serialized array
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- Custom post metadata not appearing in public API
- Get slug to point to different content of the same post
- How can I programmatically save data into custom fields that contain serialized data?
- Automatically Insert Custom Field on Custom Post Type Publish
- Using custom post type parent as slug
- Custom Post Custom Taxonomy Data Not Saving in Edit Screen
- Create a post in custom post type using field in registration form after users submit form
- WordPress custom meta field for custom post not storing data
- Conditional regex in add_rewrite_rule() for specific query filters & pagination
- List all images from a single post meta value
- Publish an XML feed from a CPT with ACF fields?
- Wrong generated page_name/slug on first publish of custom post type
- Stop / prevent WordPress from updating permalinks of custom post type
- WP_Query: include custom post type only with specific meta value
- Meta Key Value in current-user-only loop
- How can I dynamically add a post to a custom post type which uses a custom field?
- dynamically add a custom field or metabox to custom post type [duplicate]
- How to implement a Google map store locator
- Random image from tag/custom type on sidebar
- retrieve Meta field value from CPT and set those values as Image Meta Field “Title”
- Set a maxlength for the title input in a custom post type
- Update Post Meta for a logged in user
- Problem querying Custom post type by custom fields
- How to checked selected category checkbox when my custom post inserted from frontend
- Using custom field content as expression in IF statement [closed]
- ACF From & To Date Validations
- Query Multiple Custom Posts by Custom Fields
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Meta Query posts not showing on ending date of custom field
- Cross reference custom post types
- Custom Post Fields at the beginning of a Custom Permalink
- Possible to filter custom post type with multiple meta data?
- Show fields based on taxonomy selection in editor
- Permalinks: custom structure for taxonomy – tags?
- How to Get the title of a custom field?
- Specifying meta field’s column type in Database using add_post_meta
- How to find a specific post_type using its “rewrite slug”?
- detect when a custom post is cretaed for the first time
- How to customize work area / admin area in a custom post type without plugins?
- delete_post_meta() for whole CPT / multiple posts?
- How to inherit field value from parent post into in child / sub post
- How to get_term_meta on single custom post?
- How do you output an unknown number of images in a custom post type with desired markup?
- How to fetch custom post types with its full data on wordpress?
- Custom Post Type to replace Woocommerce products – page not found error
- Generating and downloading files with WP API
- Can wp_insert_post_data filter be used to save custom field data?
- Add a class to post_class if more than one post shares same meta_value_num
- Front-end Image Upload to Custom Meta Box
- How do I list a custom field and custom taxonomies for each result in a loop?
- Custom fields for post or terms which don’t update on post update
- Query custom post type that has a serialized relational advanced custom field value
- Save post action is called twice
- How can I query and sort custom-post type using WP_Query
- Meta query and compare “!=” not working as expected
- Urgent – WordPress keeps creating posts
- How to add dynamic fields on wordpress custom post type page in admin section
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- WordPress doesn’t respect Page slug in custom post type url pagination. Keeps getting removed
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Run query on specific admin options page and send results to select field in another function
- get_previous_post_link and get_next_post_link of custom post type that share custom field value
- Automatically assign posts with custom field to taxonomy term
- Error in WP Query. If variable is empty it is displaying previous post value
- custom post type archive slug vs. custom page template
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- I want to split this into two functions
- Repeatable Custom Field for Media Upload
- How to store datetime from custom meta box so that it can be sorted by
- Custom Post Meta on a Different Page?
- Adding a custom field after post title (ex.Example Title [30 Second Read])
- querying to custom field over ACF REST API
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- Custom post type Premalinks main page and details page