I think that I already found the problem. From wordpress get_posts documentation the have an example of get_post
<ul>
<?php
global $post;
$args = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="https://wordpress.stackexchange.com/questions/273344/<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
And the problem is the variable $post inside the loop, I am not sure if maybe because it cause conflicts with the other global variable $post in the line #4.
So I changed my code from this:
$countries = get_posts(array(
'post_type' => 'country',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
));
?>
<p>
<!-- my custom value Select -->
<label for="location_country_id">Country:</label>
<select name="location_country_id" id='location_country_id'>
<option value=""> -- choose Country -- </option>
<?php
if ( $countries ):
foreach ( $countries as $post ) : setup_postdata($post);
$selected = '';
if ( $current_country == $post->ID)
{
$selected = 'selected';
}
?>
<option value="<?php echo esc_attr($post->ID); ?>" <?=$selected?>><?php echo esc_html($post->post_title); ?></option>
<?php endforeach;
/* Restore original Post Data */
wp_reset_postdata();
endif;
?>
</select>
</p>
For this
$countries = get_posts(array(
'post_type' => 'country',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
));
?>
<p>
<!-- my custom value Select -->
<label for="location_country_id">Country:</label>
<select name="location_country_id" id='location_country_id'>
<option value=""> -- choose Country -- </option>
<?php
if ( $countries ):
foreach ( $countries as $country ) : setup_postdata($country);
$selected = '';
//if($player->id == $item->title)
if ( $current_country == $country->ID)
{
$selected = 'selected';
}
?>
<option value="<?php echo esc_attr($country->ID); ?>" <?=$selected?>><?php echo esc_html($country->post_title); ?></option>
<?php endforeach;
/* Restore original Post Data */
wp_reset_postdata();
endif;
?>
</select>
</p>
and No more break slug of the post.
I hope this help somebody else.