0

我有一个非常简单的代码,列出了所有自定义帖子类型,让用户使用“for each loop”从它们中进行选择,
问题是在给出选定值时它被重复,因为它已经存在,因为每个循环列表也存在..
所以我不知道如何从下拉菜单中排除用户选择的项目任何方式希望得到一些帮助提前谢谢这里是代码..

    <?php // select funeral home  ad's plugin 
$mypostype = get_posts('post_type=funeral_homes');
if($mypostype) : ?>

            <?php  
            $funeral_home_meta = get_post_meta($curpost->ID, '_selected_funeral_homes', true); 
//echo  $funeral_home_meta ;
$the_post_value = $curpost ->ID ;
//echo $the_post_value ;

$adhome_id = $funeral_home_meta;
$queried_post = get_post($adhome_id);
$ad_title = $queried_post->post_title;

?>    

<label for="my_select">Funeral home ad ? </label>
<select id="my_select" name="my_select">
<?php foreach ( $mypostype as $mypost  ) : ?>
<option value="<?php  echo $mypost->ID ;  ?>"><?php echo $mypost->post_title ?></option>
<?php endforeach; ?>
    <option value="<?php echo $funeral_home_meta ?>" selected><?php echo $ad_title 
//the proplem lays here  ?></option> 
 </select>
</form>
<?php endif ?>

至于设置选定的值,我不得不再次提及它,它是重复的,还有其他选择吗???..再次感谢.. basem

4

1 回答 1

0

如下更改您的 foreach 循环。

<?php foreach ( $mypostype as $mypost  ) :
if($mypost->ID==get_the_ID()) // check the it is current post
    continue;
?>
<option value="<?php  echo $mypost->ID ;  ?>"><?php echo $mypost->post_title ?></option>
<?php endforeach; ?>
于 2013-07-16T06:32:35.800 回答