I have created a meta box in WordPress which contains custom fields including check boxes. I am unsure as to how to check which check box has been selected from within my template.
Custom Fields
array(
"name" => "offer-type",
"title" => "Type of offer",
"description" => "Please select what kind of offer this is",
"options" => array( "TYPE A","TYPE B"),
"type" => "checkbox",
"scope" => array( "post" ),
"capability" => "edit_posts"
),
And my template loop
foreach ($posts as $day => $post) {
// 2 LINES BELOW ARE RELATED TO QUESTION
$offer_types = unserialize(get_post_meta($post->ID, "_mcf_offer-type", true));
echo var_dump($offer_types);
My var dump is returning a “false” boolean, whereas it should be returning the value of selected checkbox. Is there something wrong with the implementation?
As per our extended discussions, try calling the post via
$post('post_id')
I don’t think you need the
unserialize
either.Your whole line would become: