Metabox messes up permalink

    <?php add_action( 'add_meta_boxes', 'la_season_sponsor_add_metaboxes' );
function la_season_sponsor_add_metaboxes()
    add_meta_box( 'la_season_sponsor_metaboxid', 'League Sponsor', 'la_seasons_sponsor_metaboxes_container', 'league', 'side', 'default' );

    function la_seasons_sponsor_metaboxes_container( $post )
        $values = get_post_custom( $post->ID );
        $selected = isset( $values['la_seasons_sponsor_metabox_select'] ) ? esc_attr( $values['la_seasons_sponsor_metabox_select'][0] ) : ”;
            <select name="la_seasons_sponsor_metabox_select" id="la_seasons_sponsor_metabox_select" style="width:100%;">
                <option value="select a sponsor">Please select a sponsor</option>
                    $laleaguesponsor = array( 'post_type' => 'sponsors', 'orderby' => 'title', 'order' => 'asc', );
                    $laleaguesponsorloop = new WP_Query( $laleaguesponsor );
                    while ( $laleaguesponsorloop->have_posts() ) : $laleaguesponsorloop->the_post();
                    ?> <option value="<?php the_title(); ?>" <?php selected( $selected, get_the_title() ); ?> ><?php the_title(); ?></option>
                  <?php endwhile; wp_reset_postdata() ?>
        <input type="hidden" name="la_season_sponsor_nonce" id="la_season_sponsor_nonce" value="<?php echo wp_create_nonce( 'la_season_sponsor_nonce' ); ?>" />

add_action( 'save_post', 'la_seasons_sponsor_metaboxes_save' );
function la_seasons_sponsor_metaboxes_save( $post_id )
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    if( !isset( $_POST['la_season_sponsor_nonce'] ) || !wp_verify_nonce( $_POST['la_season_sponsor_nonce'], 'la_season_sponsor_nonce' ) ) return;

    if( !current_user_can( 'edit_post', $post_id ) ) return;

    if( isset( $_POST['la_seasons_sponsor_metabox_select'] ) )
        update_post_meta( $post_id, 'la_seasons_sponsor_metabox_select', esc_attr( $_POST['la_seasons_sponsor_metabox_select'] ) );

I’m struggling big time with this problem. I’ve made meta box which reads out sponsors, and saves it to a other cpt. Which is great.

But the metabox messes with my permalinks. It uses the last sponsor-cpt as a name. I’ve searched the forums, rebuild the code in different ways but I can’t seem to find a proper fix for it.

I don’t want to ask to many questions, because I want to learn from my own mistakes. But I’m out of options.

Thanks for the help.

Read more here: Metabox messes up permalink

Leave a Reply

Your email address will not be published. Required fields are marked *