Php Wordpress自定义小部件-保存从自定义帖子类型创建的复选框列表

Php Wordpress自定义小部件-保存从自定义帖子类型创建的复选框列表,php,wordpress,widget,checkbox,Php,Wordpress,Widget,Checkbox,这可能是一件相当标准的事情。我就是不知道该怎么做。我检查了其他各种代码,它们都在做类似的事情,但它们中的大多数似乎以与我不同的方式做事情,我不太明白 基本上,我正在创建一个简单的自定义小部件。它从一个帖子类型中提取所有帖子,并将它们显示为复选框。我需要保存哪些帖子被选中,然后将其作为数组传递,这样我就可以显示选中的帖子 要以我拥有的表单显示复选框,请执行以下操作: $postcount5 = 0; $featured_query5 = new WP_Query('showposts=5&

这可能是一件相当标准的事情。我就是不知道该怎么做。我检查了其他各种代码,它们都在做类似的事情,但它们中的大多数似乎以与我不同的方式做事情,我不太明白

基本上,我正在创建一个简单的自定义小部件。它从一个帖子类型中提取所有帖子,并将它们显示为复选框。我需要保存哪些帖子被选中,然后将其作为数组传递,这样我就可以显示选中的帖子

要以我拥有的表单显示复选框,请执行以下操作:

$postcount5 = 0; $featured_query5 = new WP_Query('showposts=5&post_type=adverts');
    while ($featured_query5->have_posts()) : $featured_query5->the_post(); 
    $do_not_duplicate[] = get_the_ID();$postcount5++;
    $currentid5 = get_the_ID();
    echo '<p><label><input type="checkbox" name="adverts" value="';
    the_id();
    echo'" ';
    if ( $currentid5 == $adboxid ) echo 'checked="yes"';
    echo '/> ';
    the_title();
    echo' </label><br/></p>';
$postcount5=0$特色搜索5=新的搜索引擎查询('showposts=5&post\u type=adverts');
而($featured_query5->have_posts()):$featured_query5->the_post();
$do_not_duplicate[]=获取_ID()$后计数5++;
$currentid5=获取_ID();
回声“”;
_title();
回音“

”;

一旦我设法救了他们,我就没事了。我就是不知道如何保存动态创建的复选框列表。提前感谢。

代码本身即使不是动态的,也无法工作。 您需要做的是重命名复选框的名称,否则只有最后一个值才可访问。例如,你可以这样做:

$postcount5 = 0; 
$featured_query5 = new WP_Query('showposts=5&post_type=adverts');
while ($featured_query5->have_posts()) : $featured_query5->the_post(); 
   $do_not_duplicate[] = get_the_ID();
   $postcount5++;
   $currentid5 = get_the_ID();

   echo '<p><label><input type="checkbox" name="adverts'.$postcount5.'" value="'.$the_id().'";
   if ( $currentid5 == $adboxid ) echo 'checked="yes"';
   echo '/> ';
   the_title();
   echo' </label><br/></p>';
<form name="postselector" action="whereever_you_want_the_user_to_go_next.php">
INSERT HERE ALL THE INPUT CHECKBOXES
AND THE SUBMIT BUTTON
</form>
if (isset($_POST['submit'])) {
   $selectedposts = array();
   $i = 0;
   foreach($_POST as $name => $value) {
      if (preg_match('adverts',$name) {
         $selectedposts[$i] = $value;
         $i++;
      }
   }
}