I have set up a Custom Post Type called <strong>Departures</strong> which also includes a Custom Meta Box to get extra variables.
Also I have set up a <strong>shortcode</strong> to get the values of the Custom Meta Box from departures, however I am struggling to echo the values of the radio button and checkboxes.
if (have_posts()) : while(have_posts()) : the_post();
// get post stuff
$custom = get_post_custom($post->ID);
$post_title = get_the_title();
$date = $custom["date"][0]; // Text Box for date
$walk = $custom["walk"][0]; // Text Box for Walk Name
$hyperlink = $custom["hyperlink"][0]; // Text Box for Hyperlink
$extra = $custom["extra"][0]; // Checkbox
$walk_type = $custom["walk_type"][0]; // Radio Button
// add to html output
$html .= '<div class="departuresbox">' ' . $date. ' <a href="'.$hyperlink.'">'.walk.'</a> '."Value of $extra".' '."Value of $walk_type".' </div>';
Below is my values for the $extra & $walk_type
echo '<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><label for="walk_type">' . __("Walk Type", 'departuresplugin_textdomain' ) . '</label></td>';
echo '<td><input type="radio" name="walk_type" value="group_guided"';
if($walk_type == 'group_guided'){echo 'checked';}else{echo '';};
echo '/> Group Guided';
echo '<br><input type="radio" name="walk_type" value="guided_walk"';
if($walk_type == 'guided_walk'){echo 'checked';}else{echo '';};
echo '/> Guided Walk</td></tr>
</table>';
echo '<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><label for="extra">' . __("Extra", 'departuresplugin_textdomain' ) . '</label></td>';
echo '<td><input type="checkbox" name="extra" value="anyday"';
if($extra == 'anyday'){echo 'checked';}else{echo '';};
echo' /> Anyday for 2 or more people booking together
echo '<br><input type="checkbox" name="extra" value="weekend"';
if($extra == 'weekend'){echo 'checked';}else{echo '';};
echo' /> Weekend only for 2 or more people booking together</td></tr></table>';
I am after the full code for the $html, that fetches the variable for the radio button and checkbox for '."Value of $extra".' '."Value of $walk_type".'
Romel Apuya answers:
$walk_type.= '<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><label for="walk_type">' . __("Walk Type", 'departuresplugin_textdomain' ) . '</label></td>';
$walk_type.='<td><input type="radio" name="walk_type" value="group_guided"';
if($walk_type == 'group_guided'){echo 'checked';}else{echo '';};
$walk_type.='/> Group Guided';
$walk_type.='<br><input type="radio" name="walk_type" value="guided_walk"';
if($walk_type == 'guided_walk'){echo 'checked';}else{echo '';};
$walk_type.='/> Guided Walk</td></tr>
</table>';
$walk_type.='<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><label for="extra">' . __("Extra", 'departuresplugin_textdomain' ) . '</label></td>';
$walk_type.='<td><input type="checkbox" name="extra" value="anyday"';
if($extra == 'anyday'){echo 'checked';}else{echo '';};
$walk_type.=' />'; Anyday for 2 or more people booking together
$walk_type.='<br><input type="checkbox" name="extra" value="weekend"';
if($extra == 'weekend'){echo 'checked';}else{echo '';};
$walk_type.=' /> Weekend only for 2 or more people booking together</td></tr></table>';
Romel Apuya comments:
$walk_type.= '<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><label for="walk_type">' . __("Walk Type", 'departuresplugin_textdomain' ) . '</label></td>';
$walk_type.='<td><input type="radio" name="walk_type" value="group_guided"';
if($walk_type == 'group_guided'){echo 'checked';}else{echo '';};
$walk_type.='/> Group Guided';
$walk_type.='<br><input type="radio" name="walk_type" value="guided_walk"';
if($walk_type == 'guided_walk'){echo 'checked';}else{echo '';};
$walk_type.='/> Guided Walk</td></tr>
</table>';
$extra.='<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%"><label for="extra">' . __("Extra", 'departuresplugin_textdomain' ) . '</label></td>';
$extra.='<td><input type="checkbox" name="extra" value="anyday"';
if($extra == 'anyday'){echo 'checked';}else{echo '';};
$extra.=' />'; Anyday for 2 or more people booking together';
$extra.='<br><input type="checkbox" name="extra" value="weekend"';
if($extra == 'weekend'){echo 'checked';}else{echo '';};
$walk_type.=' /> Weekend only for 2 or more people booking together</td></tr></table>';
parksey18 comments:
Hi,
I was after this, not the custom meta box.
$html .= '<div class="departuresbox">' ' . $date. ' <a href="'.$hyperlink.'">'.walk.'</a> '."Value of $extra".' '."Value of $walk_type".' </div>';
Romel Apuya comments:
sorry try this one out:
<?php
if (have_posts()) : while(have_posts()) : the_post();
// get post stuff
$custom = get_post_custom($post->ID);
$post_title = get_the_title();
$date = $custom["date"][0]; // Text Box for date
$walk = $custom["walk"][0]; // Text Box for Walk Name
$hyperlink = $custom["hyperlink"][0]; // Text Box for Hyperlink
$extra = $custom["extra"][0]; // Checkbox
$walk_type = $custom["walk_type"][0]; // Radio Button
$walk_type2=" ";
$extra2="";
$walk_type2.="<table width='100%' border='0' cellpadding='0' cellspacing='0'>";
$walk_type2.="<tr>";
$walk_type2.="<td width='15%'><label for='walk_type'>". __("Walk Type",'departuresplugin_textdomain')."</label></td>";
$walk_type2.="<td><input type='radio' name='walk_type' value='group_guided'";
if($walk_type == 'group_guided'){
$walk_type2.=" checked";};
$walk_type2.=" /> Group Guided";
$walk_type2.="<br><input type='radi' name='walk_type' value='guided_walk'";
if($walk_type == 'guided_walk'){
$walk_type2.=" checked";};
$walk_type2.=" /> Guided Walk</td></tr></table>";
$extra2.="<table width='100%' border='0' cellpadding='0' cellspacing='0'>";
$extra2.="<tr>";
$extra2.="<td width='15%'><label for='extra'>" . __("Extra", 'departuresplugin_textdomain' ) . "</label></td>";
$extra2.="<td><input type='checkbox' name='extra' value='anyday'";
if($extra == 'anyday'){
$extra2.=" checked";};
$extra2.=" /> Anyday for 2 or more people booking together";
$extra2.="<br><input type='checkbox' name='extra' value='weekend'";
if($extra == 'weekend'){
$extra2.=" checked";};
$extra2.=" /> Weekend only for 2 or more people booking together</td></tr></table>";
// add to html output
$html .= "<div class='departuresbox'>".$date. "<a href='".$hyperlink."'>" .$walk."</a> Value of $extra".$extra2."Value of $walk_type".$walk_type2."</div>";
echo $html;
?>
ej_emman answers:
Figure out you echo.
Change at you echo code:
echo '<td><input type="radio" name="walk_type" value="group_guided"';
//change the 'checked' to "checked" and remove the ; at the last line after } .
if($walk_type == 'group_guided'){echo "checked";}else{echo "";};
echo '/> Group Guided';
ej_emman comments:
Notice this at your code:
// No terminator
echo' /> Anyday for 2 or more people booking together
// change to this
echo ' /> Anyday for 2 or more people booking together ';
Gabriel Reguly answers:
Small fix to Romel's solution:
$html .= '
<div class="departuresbox"> ' . $date. ' <a href="'.$hyperlink.'" >' . $walk . '</a> ' . $extra2 . ' ' . $walk_type2 . '</div>';