WordPress wrong slug, slug generates from previous post slug
-
I have created a custom meta box where the list of other post appears with id and name . Now the slug of the current post is being changed according to the last id of that list. For example I have created the following post: 1. post1 2. post2
Now the slug I’m getting if I create a new post with title “Stackexchange” then the slug will appear post-3 instead of stackexchange. Again if I create a new post then it follows like post-4, post-5. I think the list of id I am population in the custom meta box is affecting the slug. How can I prevent that?
I have also tried wp_reset_postdata(), but it is still influencing the slug. Here is the code from functions.php:
`add_action(‘add_meta_boxes’, ‘add_place_metaboxes’);
function add_place_metaboxes(){
add_meta_box(‘main_parent’, ‘Select Parent Place’, ‘main_parent’, ‘places’, ‘advanced’, ‘high’);
}
function main_parent(){
global $post;
// Noncename needed to verify where the data originated
echo ‘<input type=”hidden” name=”eventmeta_noncename” id=”eventmeta_noncename” value=”‘ .
wp_create_nonce( plugin_basename(__FILE__) ) . ‘” />’;$post_id = $_GET[‘post’];
$activities = 0;
if(!empty($post_id)){
$activities = (get_post_meta( $post_id, $key = ‘custom_parent’, $single = true ));
}
$args = array(
‘post_type’ => ‘places’,
‘order’ => ‘ASC’,
‘orderby’ => ‘post_title’,
‘post_status’ => ‘publish’
);$aquery = new Wp_Query($args);
echo ‘<select name=”custom_parent[]” id=”main-parent” multiple=”multiple”>’;
if( $aquery->have_posts()): while($aquery->have_posts()): $aquery->the_post();
if(!empty($activities)){
if(in_array(get_the_ID(),$activities)){
echo “<option selected value=”.get_the_ID().”>”.get_the_title(). “</option>”;
}
else{
echo “<option value=”.get_the_ID().”>”.get_the_title(). “</option>”;
}
}
else{
echo “<option value=”.get_the_ID().”>”.get_the_title(). “</option>”;
}
endwhile; wp_reset_postdata(); endif;
echo ‘</select>’;
The topic ‘WordPress wrong slug, slug generates from previous post slug’ is closed to new replies.