[CoursePress Pro] Reorganize Units in course

Is there a way to reorganize unit sections? I need to add a new unit that supersedes all the others.

  • Jonjon

    Hello there, Eric.

    Hope you are doing great.

    I have seen what you mean and it is true. Unfortunately, as of current version CoursePress Pro 2.2.0. Re-ordering of unit sections is not supported by default, only Unit reordering.

    However, you might want to apply the workaround/solution in this thread:


    Sorry for the inconveniences and hope that helps you.

    Best Regards,

  • Jonjon

    Hi Eric.

    One more thing, I did test on current plugin version 2.2.0 and it worked very well for me :slight_smile:

    function wpmu_coursepress_replace_two_page( $array, $old_position, $new_position ) {
    	$old = !empty( $array['page_' . $old_position ] ) ? $array['page_' . $old_position ] : '' ;
    	$new = !empty( $array['page_' . $new_position ] ) ? $array['page_' . $new_position ] : '' ;
    	$array['page_' . $old_position ] = $new;
    	$array['page_' . $new_position ] = $old;
    	return $array;
    function wpmu_coursepress_replace_show_page_title( $array, $old_position, $new_position ) {
    	$old = !empty( $array[ $old_position - 1 ] ) ? $array[ $old_position - 1 ] : null ;
    	$new = !empty( $array[ $new_position - 1 ] ) ? $array[ $new_position - 1 ] : null ;
    	$array[ $old_position - 1 ] = $new;
    	$array[ $new_position - 1 ] = $old;
    	return $array;
    function wpmu_coursepress_reorder_modules() {
    	if ( isset( $_GET['wpmu_coursepress_reorder_modules'] ) ) {
    		$unit_id = 308;
    		$old_position = 1;
    		$new_position = 5;
    		if ( isset( $_GET['unit_id'] ) ) { $unit_id=  $_GET['unit_id']; }
    		if ( isset( $_GET['old_position'] ) ) { $old_position=  $_GET['old_position'];  }
    		if ( isset( $_GET['new_position'] ) ) { $new_position=  $_GET['new_position']; }
    		$page_title = get_post_meta( $unit_id, 'page_title', true );
    		$show_page_title = get_post_meta( $unit_id, 'show_page_title', true );
    		$page_description = get_post_meta( $unit_id, 'page_description', true );
    		update_post_meta( $unit_id, 'page_title', wpmu_coursepress_replace_two_page( $page_title, $old_position, $new_position ) );
    		update_post_meta( $unit_id, 'page_description', wpmu_coursepress_replace_two_page( $page_description, $old_position, $new_position ) );
    		update_post_meta( $unit_id, 'show_page_title', wpmu_coursepress_replace_show_page_title( $show_page_title, $old_position, $new_position ) );
    		global $wpdb;
    		$old_modules = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} p INNER JOIN {$wpdb->postmeta} pm ON ( p.ID = pm.post_id AND pm.meta_key='module_page' AND pm.meta_value='" . intval( $old_position ) . "' ) WHERE post_parent=" . intval( $unit_id ));
    		$new_modules = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} p INNER JOIN {$wpdb->postmeta} pm ON ( p.ID = pm.post_id AND pm.meta_key='module_page' AND pm.meta_value='" . intval( $new_position ) . "' ) WHERE post_parent=" . intval( $unit_id ));
    		foreach( $old_modules as $ID ) {
    			update_post_meta( $ID, 'module_page', $new_position );
    		foreach( $new_modules as $ID ) {
    			update_post_meta( $ID, 'module_page', $old_position );
    add_action( 'init', 'wpmu_coursepress_reorder_modules' );

    The code is the same for the post I linked, apart from the three lines I added which are:

    if ( isset( $_GET['unit_id'] ) ) { $unit_id=  $_GET['unit_id']; }
    if ( isset( $_GET['old_position'] ) ) { $old_position=  $_GET['old_position'];  }
    if ( isset( $_GET['new_position'] ) ) { $new_position=  $_GET['new_position']; }

    I added the three lines to fetch GET parameters so you can use them like shown below, without editing source code for every time unit order change you want to make. This way you can directly modify them like this:

    Again, hope this helps you and let me know if you need any assistance, I'll be glad to help.


  • Jonjon

    Hi Eric, :slight_smile:

    I'll be glad to help you out with this. I can setup the function for you and then you can edit those unit lessons.

    Would you mind providing FTP access so I can investigate this further? PLEASE DO NOT post the credentials here as forum threads are public, you can send us your details through our contact form https://premium.wpmudev.org/contact/ using this template:

    Subject: "Attn: Jonatas"
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -If you want, tell me the units you want changed, maybe I can do it for you if not too many

    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me.

    I'll be waiting for your feedback.


  • Eric Johnson

    Thanks Jon, I've been having other issues with my css on this site.

    But I would really like your help figuring this out.

    I've sent the credentials.

    Based on what you've said, I'll have a bunch to change so it might be better if I don't take to much of your time and do it myself.

    If you can set up the file for me, then I'm sure I can figure it out from there by referring back to this thread.

    Thank you!

  • Jonjon

    Hi there Eric.

    Hope you are doing great. Thank you for getting back to us.

    Anyway, I've been analyzing the script based on what you mentioned, so in Coursepress language you have 8 units with around 12 unit sections each (modules) right?

    And all you need is to enter one in the unit section at the beginning of each unit? Can you confirm that please, we might be able to modify the script so it can do that mostly automatically.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.