I want to use a metabox that allows the author to select the related post in all post edit pages.. The codes are working when publish the post, the meta is being saved.. But the post's slug is changing. For example, my post's url is "www.example.com/qwerty". After I publish the post by changing the related post, the url is "www.example.com/asdfgh-2".
"asdfgh" is previous post's slug. I am so confused, it is a very strange problem. I'm trying to solve it for days but i couldn't.. My metabox is below. Is it wrong to use a loop in a metabox?
<div class="meta-td">
<?php
// The Query
$rb_query = new WP_Query( 'posts_per_page=1000' );
// The Loop
if ( $rb_query->have_posts() ) {
echo '<select style="width:220px;" name="related-post">';
echo '<option value="none" >Select a post</option>';
while ( $rb_query->have_posts() ) {
$rb_query->the_post();
$rid = get_the_ID();
echo '<option value="';
echo $rid;
echo '"';
if ( $saved_meta['related-post'][0]== $rid ){ echo ' selected'; }
echo '>';
echo get_the_title();
echo '</option>';
}
echo '</select>';
wp_reset_postdata();
} else {
// no posts found
}
?>
</div>
save_post
code look like?