我有一个自定义的帖子类型,附带两个元框:
$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>
现在,在我的自定义wp查询中,我只想在选中复选框的情况下显示价格,因此我循环如下:
if ($meta[\'is_offered\'][0]==true){
echo \'<div class="ptitle"><p class="price">$\'.$meta[\'offer_box\'][0]. \'</p></div>\';
}
但这不是工作!你能告诉我我做错了什么吗?以下是完整的代码:
<?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;
?>