<?php
add_action( \'add_meta_boxes\', \'la_season_sponsor_add_metaboxes\' );
function la_season_sponsor_add_metaboxes()
{
// TEMP-FIX FOR FAULTY PERMALINKS
global $post, $wp_query;
$wp_query->post = $post;
// ADD META BOX
add_meta_box( \'la_season_sponsor_metaboxid\', \'League Sponsor\', \'la_seasons_sponsor_metaboxes_container\', \'league\', \'side\', \'default\' );
}
?>
<?php
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] ) : ”;
?>
<p>
<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>
<?php
$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(); ?>
</select>
</p>
<?php wp_reset_query(); ?>
<input type="hidden" name="la_season_sponsor_nonce" id="la_season_sponsor_nonce" value="<?php echo wp_create_nonce( \'la_season_sponsor_nonce\' ); ?>" />
<?php
}
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\'] ) );
}
?>
我正为这个问题苦苦挣扎。我制作了一个元框,它可以读出赞助商,并将其保存到另一个cpt。这很好。
但是代谢箱弄乱了我的永久链接。它使用最后一个赞助商cpt作为名称。我搜索了论坛,以不同的方式重建代码,但似乎找不到合适的修复方法。
我不想问太多问题,因为我想从自己的错误中吸取教训。但我别无选择。
谢谢你的帮助。