MWCreative (@mwcreative)

Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)

  • MWCreative
    Participant

    @mwcreative

    I’ve been digging around trying to find a way to move topics between forums and found a nice way to do it with php – I’ve posted the code and explanation here in case anyone is struggling:

    Bulk Move bbPress Topics PHP


    MWCreative
    Participant

    @mwcreative

    Just in case anyone needs to alter the forum of topics manually with PHP:

    1. Find the Forum ID you’re moving topics to.
    2. Create a function to search for your required topics and set the ‘post_parent’ as the forum ID. (sample below)
    3. Set the topic’s post meta fields ‘bbp_topic_forum’, ‘_bbp_topic_forum’ and ‘_bbp_forum_id’ as the Forum ID.
    4. Repair the forums (tools->forums)

    After these steps you should see your topics in the correct forum!

    Place in functions.php file of your child theme and modify to your needs, then call the function:
    ** Disclaimer! I’m not responsible for breaking your site! backup your install before using this code to change your topics! **

    function mwc_change_forum_topic_ties() {
            
            // 18 was my target forum ID.  get yours.
    	$forumid = '18';
    	
    	$args = array(
    		'post_type' => 'topic',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    	);
    
            /* uncomment this to filter your topics by something
    
            $oldForumID = '10'; //change this to target a specific forum
            $args['meta_query'] = array(
                    'meta_key' => 'bbp_topic_forum',
                    'meta_value' => $oldForumID,
                    'compare' => '='
            );
    
            */
    	
    	$query = new WP_Query( $args );
    	
    	if($query->have_posts()):
    		while($query->have_posts()):
    			$query->the_post();
    			$theid = get_the_ID();
    			
    			$theargs = array(
    				'ID' => $theid,
    				'post_parent' => $forumid
    			);
    			
    			wp_update_post($theargs);
    			
    			update_post_meta($theid, 'bbp_topic_forum', $forumid);
    			update_post_meta($theid, '_bbp_topic_forum', $forumid);
    			update_post_meta($theid, '_bbp_forum_id', $forumid);
    			update_post_meta($theid, '_bbp_topic_id', $theid);
    			
    		endwhile;	
    	endif;
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)