What fields will determine the title?
My custom fields that I have defined via PODS. But to the question, how best can I access the post_title field during ‘pre_save_pod_item’ action?
The POD is created from a custom post type
Check out the docs for the pre_save filter:
http://pods.io/docs/code/filter-reference/pods_api_pre_save_pod_item_podname/
You should be able to set, in your pre_save filter, to set the post title value with $pieces[ 'fields' ][ 'post_title' ][ 'value' ] = "WHATEVER_YOU_WANT_TITLE_TO_BE";
How would that work? I tried this via functions.php, but I am still getting the same “Auto Drafts” for all items.
Josh, pods_api_pre_save_pod_item does not work because $pieces[‘fields’] only refers to custom meta fields. The default post fields such as ‘post_title’ are only found in: $pieces[‘object_fields’]. However, these only appear to be field descriptors because there is no ‘value’ property to any of these fields.
Gattermeier, here is my current hack for this POD bug. Hook into the ‘wp_insert_post_data’ filter, which runs for every post add/edit/update. To access the metadata, use: $postarr[ ‘pod_meta_%my_meta_name%’]. By the way, this filter runs BEFORE pods_api_pre_save_pod_item.
function wp_pre_save( $data , $postarr ) {
//$data['post_title'] = $postarr['pods_meta_width'].'x'.$postarr['pods_meta_length'];
if ($data['post_type'] == 'metal_building') {
$width = $postarr['pods_meta_width'];
$length = $postarr['pods_meta_length'];
if (!empty($width) && !empty($length)) {
$data['post_title'] = $data['post_name'] = $width.'x'.$length;
}
}
return $data;
}
add_filter( 'wp_insert_post_data', array($this,'wp_pre_save'), '99', 2 );
Thank you unity3software. However, trying to add this has a peculiar effect. Suddenly I am not able anymore to save any post, yet alone publish. The functionality seems limited to “submit for review” for all content types, including posts and pages.
Any idea?