Hi guys and gals,
I'm trying to add a checkbox within the WordPress Editor (Admin panel) that triggers a predetermined function that changes the current post.
Basically, I have a product page (with lots and lots of products). When I edit the post for that specific product, there'll be a check box stating if the product is sold out or not. When checked, the site will display a "Sold Out" image at the top of entry div. When not, nothing will display there.
I'm not exactly sure how to get about this. Do I need a plug in or sorts?
Thanks! :)
You can give the product a category "sold" or use custom fields or adding a metabox with the checkbox to the editor page.
There are probably plugins that can do this also.
Hmm, ok I just installed a metabox plug in, do I just use the get_post_custom() to detect if the checkbox is checked?
It doesn't show what values it returns. Or does checkboxes just return a "true/false" value?
What plugin are you using?
This one : http://wordpress.org/extend/plugins/verve-meta-boxes/installation/
Verve Meta Boxes
I think I got it working. It pops up and alert when checked and doesn't when not. Now I just need to figure out how set it to differentiate each individual post.
Here's the code I placed in the_loop
<?php
$detect_sold_out = get_post_custom_values('sold_out');
if ($detect_sold_out == true) { ?>
<script> alert('it works') </script>
<?php } ?>
:)
Try looking what $detect_sold_out holds:
$detect_sold_out = get_post_custom_values('sold_out');
echo $detect_sold_out;
// or
echo '<pre>';
print_r($detect_sold_out);
echo '</pre>';