Title: conditional ineffective
Last modified: September 14, 2023

---

# conditional ineffective

 *  [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/)
 * I decided to add `' &euro;'.'/ sett.'` in this function:
 *     ```wp-block-code
       $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' . get_post_meta( $post->ID, 'function_prezzo_secondo', true ). ' &euro;'.'/ sett.' ;
       if ( ! empty( $display_price2)) {
       $display_price2='<div class="listino_prezzi">'. $display_price2 .'</div>';
       }
       ```
   
 * But I’m realizing that, doing so, the conditional `if ( ! empty( $display_price2))`
   is unusefull because the variable `$display_price2` will never be empty. The 
   is a remedy to this?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048341)
 * Just add it later
 *     ```wp-block-code
       $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' . get_post_meta( $post->ID, 'function_prezzo_secondo', true );
       if ( ! empty( $display_price2)) {
       	$display_price2='<div class="listino_prezzi">'. $display_price2 .' &euro; / sett</div>';
       }
       ```
   
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048394)
 * Also in this way the variable is printed. I tryed to put also `.' &euro; / sett`
   out of the div but i got printed both a white div and under this “€ / sett.”
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048626)
 * Why do you want “€ / sett” outside of the div? Divs are normally block level 
   elements, so added content will typically appear below the div and any margins
   and padding from the div will separate the two.
 * If you want “€ / sett” styled differently than other div content but still on
   the same line, place it within `<span>` tags, which display as inline elements.
   Assign a class attribute to the span so you can target it with CSS separately
   from other div content.
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048636)
 * I dont want it out of the div, I want the conditional be working
 * Here you shouldnt see the grid with green lines: [https://test.sacconicase.com/lignano-sabbiadoro-appartamento-al-1-piano-con-terrazzo-spazioso-zona-ufficio-spiaggia-16/#titolo_listino_prezzi](https://test.sacconicase.com/lignano-sabbiadoro-appartamento-al-1-piano-con-terrazzo-spazioso-zona-ufficio-spiaggia-16/#titolo_listino_prezzi)
 * because both get_the_author_meta and get_post_meta are empty, but “€ / sett ruins
   the function
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048661)
 * Sorry, what was wrong with my code? Did you try it?
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048673)
 * I just spotted you added a space as well so to make the empty work then trim()
 *     ```wp-block-code
       $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' . get_post_meta( $post->ID, 'function_prezzo_secondo', true );
       if ( ! empty( trim( $display_price2 ) )) {
       	$display_price2='<div class="listino_prezzi">'. $display_price2 .' &euro; / sett</div>';
       }
       ```
   
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17048755)
 * It would have worked (it has worked), but the problem is that now there is no
   more that space, it is replaced with a ‘ <strong>’ , with a space too, so when
   I use
 *     ```wp-block-code
       $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' <strong>' . get_post_meta( $post->ID, 'function_prezzo_secondo', true ).'</strong>';
       if ( ! empty(trim( $display_price2 ) )) {
       	$display_price2='<div class="listino_prezzi">'. $display_price2 .' &euro; / sett</div>';
       }
       ```
   
 * I still have this problem (with or without the trim) 🙁 sorry for this changment,
   I’m trying to adjust the code to the project
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17051493)
 * We’re now discussing the same code snippet in two different topics. The cross-
   talk can be confusing for everyone involved. This is why we discourage duplicate
   topics. I realize that these topics were initially focused on two different aspects,
   but now they’ve run together.
 * To keep further replies in one place, this topic is now closed. Please continue
   at [https://wordpress.org/support/topic/crating-a-function-to-set-discount-on-prices/#post-17049761](https://wordpress.org/support/topic/crating-a-function-to-set-discount-on-prices/#post-17049761)

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘conditional ineffective’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 8 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/conditional-ineffective/#post-17051493)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
