samedi 14 novembre 2015

wordpress automatically add category on custom post type

I have created 3 custom post types, using wp-types plugin and Cred front editor plugin: 1. Listino (pl.Listini) 2. Negozio (pl. Negozi) 3. Consegna-listino (pl. Consegna-listini)

Post types #3 are children of post-types # 1 and 2. I want post that every post type #3 automatically get the category-term of the parent #2.

I've tried this function: but is doesn't work:

add_action('cred_save_data_242', 'save_data_for_form_with_id_242', 10, 2);
function save_data_for_form_with_id_242($post_id, $form_data) {
$parent_ID = get_post_meta($post_id, "_wpcf_belongs_listino_id", true);
$parent_Cat = wp_get_post_categories( $parent_ID );
$my_taxonomy = 'category';
$term_list = wp_get_post_terms($parent_ID, $parent_Cat, array("fields" => "ids"));

wp_set_post_terms($post_id, $term_list, $my_taxonomy);
}
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire