I am using the WordPress theme WPJobus and I had the necessity to modify the workflow of Resume Submission and Resume Editing.
The functions which provide for these operations are located as usual into the file /mytheme/functions.php
wpjobusSubmitResumeForm()
wpjobusEditResumeForm()
On both of them I have removed the whole code portion which switch post status to “Draft” on every edit occurrence, since I needed to give to the new user the possibility to insert their own posts (Resumes) and publish without the Administrator supervision.
Anyway, I made the all changes and everything works fine except the function wp_update_post() with posts.post_title field!
The code looks like this:
$post_information = array(
'ID' => $td_current_post,
'post_title' => $_POST['fullName'],
'post_content' => strip_tags($_POST['postContent']),
'post_type' => 'resume',
'post_name' => $td_current_post,
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_status' => 'publish'
);
$td_post_id = wp_insert_post($post_information);
wp_update_post(
array(
'ID' => $td_post_id,
'post_name' => $td_post_id
)
);
The INSERT works fine but when I call the UPDATE, which is absolutely necessary for post_name field, post_name is correctly updated while post_title value is deleted.
I got the same effect even if I try to pass ‘post_title’=>$_POST[‘fullName’] within wp_post_update array.
Anyone had the same issue?
I also found this but it didn’t help at all:
wp_update_post inserts empty title and content
Thank you for your answer doublesharp!
I finally found the origin of the problem just reading carefully the functions.php file row by row.
The function which was causing the problem is filter_handler() on line 636.
In this case for me it was enough to comment the hook add_filter() related to this function and I achieved the goal.
Now, if I run the script above, wp_post_update() works like a charm with Resume Post Type ( I guess with Company and Job Post Types as well ).
I will make some more tests and will update this thread in case I would face some unexpected issue.
Here the code of the function:
Another solution should be to force the call of filter_handler() Only if the current user is Administrator using the related ‘controller’:
For sure the problem is located within that function so any possible correction must be done on it.
Now that you have provided more information, the correct way to change this behavior is to remove the filter that is being added by your theme, which will give you control of the
post_title
.Without access to the source code for your theme it’s not possible to say where the error is coming from, however you should be able to use the
pre_update_posts
action to debug, and possibly correct the behavior using thewp_insert_post_data
filter.To use the
pre_update_posts
for debugging, you can print the contents of the$data
array that is used to update theposts
table, and the$postarr
array which contains the original fields that you passed in (it can’t be modified using filters).The last available place to modify post data that is being inserted/updated is in the
wp_insert_post_data
filter. By attaching to this filter later than everything else, you have the final say in the array values.