I am developing a plugin for custom post type which take the link from the title of the post and then after scraping on that link it updates all things like post title, post permalink and post_meta. Now its only updating the title and the link but not the post meta, I have tried debugging the data.
function a_new_post($new_status, $old_status, $post)
{
if ('publish' !== $new_status or 'publish' === $old_status)
return;
$new_slug = sanitize_title($post->post_title);
if ('aps-products' !== $post->post_type)
return; // restrict the filter to a specific post type
$result= getSpecs($post->post_title);
/*
******************************************************************************
******************************************************************************
******************************************************************************
*/
$groups = get_aps_cat_groups(16);
$groups_data = get_aps_groups_data();
$attrs_data = get_aps_attributes_data();
// get aps attributes data from input fields
foreach ($groups as $groupId) {
$group_data = $groups_data[$groupId];
$group_values = get_aps_product_attributes($post->ID, $groupId);
if ($group_data['attrs']) {
if (aps_is_array($group_data['attrs'])) {
$first=array();
$value='';
foreach ($group_data['attrs'] as $attr_id) {
switch($attr_id){
case 20:
$value=$result[1];
break;
case 21:
$value=$result[12];
break;
case 22:
$value=$result[3];
break;
case 24:
$value=$result[13];
break;
}
$frist[$attr_id]=$value;
}
update_post_meta( $post->ID, 'aps-attr-group-' .$groupId, $first );
}
}
}
/*
******************************************************************************
******************************************************************************
******************************************************************************
*/
$post_update = array(
'ID' => $post->ID,
'post_title' => $result[0].' '.$result[1]
);
if (!wp_is_post_revision($post->ID)) {
wp_update_post($post_update);
$new_slug = sanitize_title($result[0].' '.$result[1]);
if ($post->post_name != $new_slug) {
wp_update_post(
array(
'ID' => $post->ID,
'post_name' => $new_slug
)
);
}
}
}