我的帖子里面有一个检查按钮。这个表单的结果存储在我的wordpress安装中的wp_postmeta表中,作为序列化的数据数组,例如,如下所示:
a:2:{s:19:"Ain’t No Sunshine";s:7:"do_play";s:15:"Summer of ’69";s:7:"do_play";}
当我在我的页面中回应这个时,使用以下代码:
print_r(get_post_meta($booking_query->post->ID, 'songChoices', true)
我得到以下内容:
Array ( [Ain’t No Sunshine] => do_play [Summer of ’69] => do_play ) 1
以下是我的表格代码:
<form id="songChoices-12028" method="POST">
<input type="hidden" id="booking_id" name="booking_id" value="12028">
<ul class="setlist_container">
<li class="song_entry ">Ain’t No Sunshine -
<em>Bill Withers</em>
<br>
<input type="radio" id="doPlay" name="songChoices[Ain’t No Sunshine]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[Ain’t No Sunshine]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
<li class="song_entry ">No Diggity -
<em>Blackstreet</em>
<br>
<input type="radio" id="doPlay" name="songChoices[No Diggity]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[No Diggity]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
<li class="song_entry 7-8-piece drinks-reception">Pricetag -
<em>Jessie J</em>
<br>
<input type="radio" id="doPlay" name="songChoices[Pricetag]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[Pricetag]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
<li class="song_entry 4-5-piece">Rehab -
<em>Amy Winehouse</em>
<br>
<input type="radio" id="doPlay" name="songChoices[Rehab]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[Rehab]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
<li class="song_entry 4-5-piece">Rolling in the Deep -
<em>Adele</em>
<br>
<input type="radio" id="doPlay" name="songChoices[Rolling in the Deep]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[Rolling in the Deep]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
<li class="song_entry 4-5-piece">Sittin’ on the Dock of the Bay -
<em>Otis Redding</em>
<br>
<input type="radio" id="doPlay" name="songChoices[Sittin’ on the Dock of the Bay]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[Sittin’ on the Dock of the Bay]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
<li class="song_entry 4-5-piece">Summer of ’69 -
<em>Bryan Adams</em>
<br>
<input type="radio" id="doPlay" name="songChoices[Summer of ’69]" value="do_play">
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[Summer of ’69]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
</ul>
<button type="submit">Submit</button>
</form>
这些复选框中的每一个都是在php文件中动态创建的,该文件为每首歌曲自定义帖子类型创建一个列表项 - 这是生成上面的html的php,它位于wordpress循环中:
<li class="song_entry <?php echo $setlistBand;?>"><?php echo get_the_title(); ?> -
<em><?php echo $setlistArtist; ?></em>
<br />
<input type="radio" id="doPlay" name="songChoices[<?php echo esc_html(get_the_title()); ?>]" value="do_play" >
<label for="doPlay">Do</label>
<input type="radio" id="dontPlay" name="songChoices[<?php echo esc_html(get_the_title()); ?>]" value="dont_play">
<label for="dontPlay">Don't</label>
<a href="#" id="clear-button">Clear</a>
</li>
我想在上面添加一行,检查是否选中了收音机盒并将其打开以显示结果。例如,应该在页面加载时检查“不是没有阳光”的复选框,因为它在数据库中标记为do_play