Support

Account

Home Forums Front-end Issues Relational if get

Solved

Relational if get

  • Hello,

    i’ve have a CPT with some CPF.

    I have two group of field, for summer price (name summer_price and is a true/false field). In “Summer Price” i have the field for price (week, week in august, week in july, day, day in august etc).

    And i have “Winter Price” (name winter_price) with field similar as summer price.

    I’ve create a table on my single-cpt.php and i need to see the group “Summer Price” only if summer_price is true. Also i neet to see the bloc “Price Week” only if one of the field inside group (price week) have a text.

    My code is here:

    But nothing happend if i not select the field “Summer Price” (every time i see the price on group summer_price”.

    <!--Mostra Prezzi se Selezionato Estate -->          
    <?php if ( get_field( 'stagione-estiva' ) ): ?>          
    <table class="table table-bordered tours-tabs__table" width="900" style="height: 233px;">
    <tbody>
    <?php if ( get_field( 'stagione-estiva' ) ): ?>   
    <tr>  
    <td>
    <strong>TARIFFA SETTIMANALE</strong>    
    </td>
    <td>
    <?php the_field('tariffa_settimanale_1'); ?> <br>
    <?php the_field('tariffa_settimanale_2'); ?><br>
    <?php the_field('tariffa_settimanale_3'); ?><br>
    <?php the_field('tariffa_settimanale_4'); ?>
    </td>
    </tr>
    <?php endif; ?>
    
    <?php if ( get_post_meta( get_the_ID(), 'tariffa_mensile_1', true ) ) : ?>
    <tr>
    <td>
    <strong>TARIFFA MENSILE</strong>
    </td> 
    <td>
    <?php the_field('tariffa_mensile_1'); ?><br>
    <?php the_field('tariffa_mensile_2'); ?><br>
    <?php the_field('tariffa_mensile_3'); ?>
    </td>
    </tr> 
    <?php endif; ?>
    <?php if ( get_post_meta( get_the_ID(), 'tariffa_stagionale_1', true ) ) : ?>
    <tr>
    <td>
    <strong>TARIFFA STAGIONALE</strong>
    </td>
    <td>
    <?php the_field('tariffa_stagionale_1'); ?><br>
    <?php the_field('tariffa_stagionale_2'); ?><br>
    <?php the_field('tariffa_stagionale_3'); ?><br>
    <?php the_field('tariffa_stagionale_4'); ?>
    </td>  
    </tr> 
    <?php endif; ?> 
    </tbody>
    </table>
    <?php endif; // end of if field_name logic ?>

    Also if i try to setting this

    <?php if ( get_post_meta( get_the_ID(), 'tariffa_mensile_1', true ) ) : ?>
    or
    <?php if ( get_post_meta( get_the_ID(), 'tariffa_mensile_2', true ) ) : ?>

    I have a withe page.

    So i like to make this:

    – If “Summer Price” (true/false field) is check see on front-end the table with field inside this conditional group of field. If not check see nothing.
    – If one of the field “tariffa_mensile_1” or “tariffa_mensile_2” or “tariffa_mensile_3” have text so see on front-end this content on table “Tariffa Mensile”.

    Thanks much

  • Hi @serviceweb

    Regarding your first request, I’m afraid I don’t see what’s wrong with the code. Could you please explain it to me in more detail and share some screenshots of the issue on the backend and front end?

    Regarding your second request, could you please try the following code?

    <?php if ( get_field('tariffa_mensile_1') || get_field('tariffa_mensile_2') || get_field('tariffa_mensile_3') ) : ?>
    	<tr>
    		<td>
    			<strong>TARIFFA MENSILE</strong>
    		</td> 
    		<td>
    			<?php the_field('tariffa_mensile_1'); ?><br>
    			<?php the_field('tariffa_mensile_2'); ?><br>
    			<?php the_field('tariffa_mensile_3'); ?>
    		</td>
    	</tr> 
    <?php endif; ?>

    Hope this helps. Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.