Skip to main content
clarified question.
Source Link
glu
  • 65
  • 6

Conditional display for custom fields/taxonomy

If there's a value for the custom field, I want it to display the value. If there's no value for the custom field, I want it to display "N/A". I have this working for custom fields but cant replicate the same functionality for a custom taxonomy.

This works for a custom field:

$url = get_post_meta( get_the_ID(), 'event-code', true );
if ( ! empty( $url ) ) {
print ( $url );
}
else {
print 'N/A';
}

But for entriesIn the case of a custom taxonomy entry with a value, this displays both the value and "N/A":

$promtax = the_terms( get_the_ID(), 'promotion','' );
if ( ! empty( $promtax ) ) {
print ( $promtax );
}
else {
print 'N/A';
}

I've used variations and combinations of isset, empty without any luck. Thanks.

Conditional display for custom fields

If there's a value for the custom field, I want it to display the value. If there's no value for the custom field, I want it to display "N/A".

This works:

$url = get_post_meta( get_the_ID(), 'event-code', true );
if ( ! empty( $url ) ) {
print ( $url );
}
else {
print 'N/A';
}

But for entries with a value, this displays both the value and "N/A":

$promtax = the_terms( get_the_ID(), 'promotion','' );
if ( ! empty( $promtax ) ) {
print ( $promtax );
}
else {
print 'N/A';
}

I've used variations and combinations of isset, empty without any luck. Thanks.

Conditional display for custom fields/taxonomy

If there's a value for the custom field, I want it to display the value. If there's no value for the custom field, I want it to display "N/A". I have this working for custom fields but cant replicate the same functionality for a custom taxonomy.

This works for a custom field:

$url = get_post_meta( get_the_ID(), 'event-code', true );
if ( ! empty( $url ) ) {
print ( $url );
}
else {
print 'N/A';
}

In the case of a custom taxonomy entry with a value, this displays both the value and "N/A":

$promtax = the_terms( get_the_ID(), 'promotion','' );
if ( ! empty( $promtax ) ) {
print ( $promtax );
}
else {
print 'N/A';
}

I've used variations and combinations of isset, empty without any luck. Thanks.

Tweeted twitter.com/#!/StackWordPress/status/96695011869081600
Source Link
glu
  • 65
  • 6

Conditional display for custom fields

If there's a value for the custom field, I want it to display the value. If there's no value for the custom field, I want it to display "N/A".

This works:

$url = get_post_meta( get_the_ID(), 'event-code', true );
if ( ! empty( $url ) ) {
print ( $url );
}
else {
print 'N/A';
}

But for entries with a value, this displays both the value and "N/A":

$promtax = the_terms( get_the_ID(), 'promotion','' );
if ( ! empty( $promtax ) ) {
print ( $promtax );
}
else {
print 'N/A';
}

I've used variations and combinations of isset, empty without any luck. Thanks.