Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function migre_post_to_bp_docs() {
- global $wpdb;
- // le tag ayant pour nom tagA aura pour slug taga
- // un petit tableau de corresp
- $corresp['taga'] = array( 'tag_slug' => 'taga', 'group_id' => 3);
- /*si plusieurs du type
- $corresp['tagb'] = array( 'tag_slug' => 'tagb', 'group_id' => 4);
- ..
- if faudra boucler sur le tableau corresp pour lancer ce qui suit :
- */
- $group_ids = $wpdb->get_col("SELECT id FROM {$wpdb->base_prefix}bp_groups");
- if( count( $group_ids ) >= 1) {
- foreach( $group_ids as $group_id ){
- if( $group_id == $corresp['taga']['group_id'] ) {
- // a-t-on des posts dans le tagA ?
- $args = array(
- 'tax_query' => array(
- array(
- 'taxonomy' => 'post_tag',
- 'field' => 'slug',
- 'terms' => $corresp['taga']['tag_slug']
- )
- )
- );
- $postslist = get_posts( $args );
- // si on a des posts... on poursuit
- if( count( $postslist ) >= 1 ) {
- // bp doc activé sur le groupe
- $bpdoc_is_active = groups_get_groupmeta( $group_id, 'bp-docs');
- //si pas le cas on active
- if( empty( $bpdoc_is_active ) ) {
- $default_group_setting = array('group-enable' => "1", "can-create" => "member");
- groups_update_groupmeta( $group_id, 'bp-docs', $default_group_setting);
- }
- // créons la custom taxo de bp doc pour ce group avant de modifié le post type puis de l'assigner à cette taxo.
- if( $term_id = bp_docs_get_item_term_id( $group_id, 'group' ) ) {
- foreach( $postslist as $new_bp_doc ) {
- set_post_type( $new_bp_doc->ID, bp_docs_get_post_type_name() );
- wp_set_post_terms( $new_bp_doc->ID, array( $term_id ), bp_docs_get_associated_item_tax_name(), false);
- }
- }
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement