Reputation: 15
I'm trying to remove certain part of the post if:
property-type&tag_ID=13
The content I'm trying to hide is:
<div class="single-property-meta clearfix status-<?php echo $status_id; ?>-text">
<?php
$meta_size = get_post_meta( $post->ID, 'property_size', true );
**$meta_bedrooms = get_post_meta( $post->ID, 'property_bedrooms', true );
$meta_bathrooms = get_post_meta( $post->ID, 'property_bathrooms', true );
$meta_garages = get_post_meta( $post->ID, 'property_garages', true );
$meta_address = get_post_meta( $post->ID, 'property_address', true );**
?>
<span class="meta-size"><i class="ico-size"></i><?php echo $meta_size; ?></span>
**<span class="meta-bedroom"><i class="ico-bedroom"></i><?php echo $meta_bedrooms.'<span class="meta-hidden">'.__( ' Bedrooms' ).'</span>'; ?></span>
<span class="meta-bathroom"><i class="ico-bathroom"></i><?php echo $meta_bathrooms.'<span class="meta-hidden">'.__( ' Bathrooms').'</span>'; ?></span>
<span class="meta-garage"><i class="ico-garage"></i><?php echo $meta_garages.'<span class="meta-hidden">'.__( ' Garages').'</span>'; ?></span>**
<span class="meta-print visible-desktop"><i class="ico-print"></i><span class="print-hidden"><a href="javascript:window.print()"><?php echo __( 'Print this page'); ?></a></span></span>
<span class="meta-status"><?php echo $property_status; ?></span>
</div>
Any help would be welcome, I know I have to use some sort of a IF statement to show the content only IF the ID is = 13. All I have right now is this:
if ($property-type&tag_ID=13) {
}
Upvotes: 0
Views: 98
Reputation: 26066
Very valid question. This is part of the reason I hate mixing HTML with PHP. It makes it all seem so complicated when it really is very simple. So change these lines:
$meta_bedrooms = get_post_meta( $post->ID, 'property_bedrooms', true );
<span class="meta-bedroom"><i class="ico-bedroom"></i><?php echo $meta_bedrooms.'<span class="meta-hidden">'.__( ' Bedrooms' ).'</span>'; ?></span>
To be these using pure PHP:
if ($property-type && $tag_ID != 13) {
$meta_bedrooms = get_post_meta( $post->ID, 'property_bedrooms', true );
}
<?php
if ($property-type && $tag_ID != 13) {
echo '<span class="meta-bedroom">'
. '<i class="ico-bedroom"></i>'
. $meta_bedrooms
. '<span class="meta-hidden">'
. __( ' Bedrooms' )
. '</span>'
. '</span>'
;
}
?>
First note that your initial example if
of ($property-type&tag_ID=13)
is wrong since tag_ID=13
(note one =
) is an assignment of a value. Also you have tag_ID
set when it should be a variable like $tag_ID
. So the final check as I have it is now $tag_ID != 13
since you want to hide items if $tag_ID
is 13
, which means you only want to show that content if $tag_ID
is 13
so if $tag_ID != 13
is set anything else will show the content, but if it is equal to 13
it is hidden.
That said, what is $property-type
and what is the check there? The way I have it set it will be TRUE
if there is any value set to $property-type
, but perhaps that’s not needed and the conditional should simply be if ($tag_ID != 13) {
.
That said, cleaning things up reveal other potential issues. Such as, what exactly is the purpose of this <i class="ico-bedroom"></i>
? An <i>
tag that closes itself right away? Your other <span>
tags have similar <i>
tags. Intentional?
Upvotes: 0
Reputation: 4099
Wrap the part you wanna hide with:
<?if ($property-type && $tage_ID=13) {?>
your hidden part
<?}?>
Actually Im not sure what $property-type&tag_ID=13
is.
Upvotes: 2