Created
October 9, 2012 11:27
-
-
Save aendra-rininsland/3858114 to your computer and use it in GitHub Desktop.
Snippets of WP Alchemy multidimensional code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* I'm using WP Alchemy as a way to select images that have been pulled from a Pinterest board. | |
* As a result, each image has two properties: URL and Title. | |
* All the examples for the Checkbox/Multicheckbox form type involve feeding a simple array into a loop of some sort: | |
*/ | |
?> | |
<?php $items = array('a', 'b', 'c'); ?> | |
<?php foreach ($items as $i => $item): ?> | |
<?php $mb->the_field('cb_ex2', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?> | |
<input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/> | |
<?php endforeach; ?> | |
<?php | |
/** | |
* My $items array is necessarily multi-dimensional: | |
*/ | |
?> | |
<?php | |
$items[] = array( | |
'title' => 'A Title', | |
'url' => 'http://something.com' | |
); | |
?> | |
<?php | |
/** | |
* ...With each image having its own array containing a title and URL. | |
* | |
* My input thus looks like: | |
*/ | |
?> | |
<input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item['url']; ?>"<?php $mb->the_checkbox_state($item['url']); ?>/> <?php echo $item['title']; ?><br/> | |
<?php | |
/** | |
* However, I'm experiencing a weird bug where whatever's selected first persists across all posts | |
* -- for instance, when I click to create a new post of this content type, the values I selected | |
* the very first time are pre-selected. I can't even change them in the first post, they just revert back. | |
* | |
* My guess is that passing an array key to the_checkbox_state(); like I've done is causing stuff to not work. | |
* Any thoughts? Thanks! | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment