0

I have a Custom Post Type with two Metabox attached as:

$offerPrice = isset( $productValuesl['offer_box'] ) ? esc_attr( $productValuesl['offer_box'][0] ) : '';    
$offer = isset( $productValuesl['is_offered'] ) ? esc_attr( $productValuesl['is_offered'][0] ) : '';

<tr>
<td ><label for="price_box">Product Price : </label></td>
<td align="left"><input type="text" name="price_box" id="price_box" value="<?php echo $price; ?>" /></td>
</tr> 

<tr>
<td align="" style=""><label for="is_offered">Show Offer :</label></td> 
<td align="left"><input type="checkbox" name="is_offered" id="is_offered" <?php checked( $offer, 'on' ); ?> /></td>

now in my custom wp-query I would like to display the price ONLY if the check box is checked so I did a loop as:

if ($meta['is_offered'][0]==true){
  echo '<div class="ptitle"><p class="price">$'.$meta['offer_box'][0]. '</p></div>';
}

but it is not doing the job! can you please let me know what I am doing wrong? Here is the entire code:

<?php
$args = array( 'post_type' => 'sunglassesCPT', 'posts_per_page' => 1000, 'orderby' => 'name', 'order' => 'ASC'  );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$meta = get_post_custom($post->ID);
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
echo '<div class="col-sm-6 col-md-4">';
echo '<div class="thumbnail text-center">';
echo '<div class="productImgBox" style="height:220px;">';
the_post_thumbnail('', array('class' => 'img-responsive', 'href' =>$thumb_url));
echo '</div>';
echo '<div class="caption">';
echo '<h4 class="product-title">'.the_title().'</h4>';
if ($meta['is_offered'][0]==true){
  echo '<div class="ptitle"><p class="price">$'.$meta['offer_box'][0]. '</p></div>';
}
echo '<p><a href="'.$thumb_url.'" class="btn btn-sm btn-brown group1" title="Rumi Optical Eyeglasses" role="button">Quick View</a></p>';
echo '</div>';
echo '</div>';
echo '</div>';
endwhile;
?> 
1
  • 1
    Please dont post same question in a network. You have already posted this in stackoverflow. Apr 30, 2015 at 3:47

1 Answer 1

1

One thing you might want to do is add this code to the output:

<pre><?php print_r($meta); ?></pre>

Then have a look and make sure you are accessing the correct array keys.

Once your sure, I think you need to verify checkboxes against a value of on or off. So you may need to change this line:

if ($meta['is_offered'][0]==true){

... to this ...

if ($meta['is_offered'][0] === on){
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.