Title: Shortcode conditional
Last modified: May 2, 2021

---

# Shortcode conditional

 *  Resolved [nanny7](https://wordpress.org/support/users/nanny7/)
 * (@nanny7)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/shortcode-conditional/)
 * Hi I am using this:
 *     ```
       function shortcode_acf_tablefield( $atts ) {
   
           $a = shortcode_atts( array(
               'table-class' => '',
               'field-name' => false,
               'post-id' => false,
           ), $atts );
       $tables = (get_field( 'add_members_table' ) == 'yes');
   
       if ( ! empty ( $tables ) ) {
   
           $table = get_field( $a['field-name'], $a['post-id'] );
       	$caption_text = get_field( 'table_name', $a['post-id'] );
   
           $return = '';
   
           if ( $table ) {
       		 $return .= '<h2>' . $caption_text . '</h2>';
   
               $return .= '<table class="' . $a['table-class'] . '" border="0">';
   
                   if ( ! empty( $table['caption'] ) ) {
   
                       echo '<caption>' . $table['caption'] . '</caption>';
                   }
   
                   if ( $table['header'] ) {
   
                       $return .= '<thead>';
   
                           $return .= '<tr>';
   
                               foreach ( $table['header'] as $th ) {
   
                                   $return .= '<th scope="col">';
                                       $return .= $th['c'];
                                   $return .= '</th>';
                               }
   
                           $return .= '</tr>';
   
                       $return .= '</thead>';
                   }
   
                   $return .= '<tbody>';
   
                       foreach ( $table['body'] as $tr ) {
   
                           $return .= '<tr>';
       						 $i = 0;
                               foreach ( $tr as $td ) {
   
                                   $return .= '<td data-column="' . $table['header'][$i]['c'] . ':">';
                                       $return .= $td['c'];
                                   $return .= '</td>';
       							$i++;
                               }
   
                           $return .= '</tr>';
                       }
   
                   $return .= '</tbody>';
   
               $return .= '</table>';
           }
   
           return $return;
       }
   
       }
   
       add_shortcode( 'tablefield', 'shortcode_acf_tablefield' );
       ```
   
 * But I am wanting to add an addition to the conditional if they have not selected
   the table but want to upload a pdf etc. instead. I have the buttons in acf working
   correctly and if the field is “no” the table doesn’t show.
 * I am trying to add this as an else
 *     ```
       $pdf = (get_field( 'add_members_table' ) == 'no');
       if ( ! empty ( $pdf ) ) {
       $content_type = get_field('choose_which_file_to_show');
           if ($content_type == 'PDF') { ?>
        <img class="align-middle" src="<?php echo get_stylesheet_directory_uri(); ?>/img/pdf.png" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="32" height="32" /> <a href="<?php the_field('upload_pdf'); ?>" ><?php the_title(); ?></a>
        <?php
       } 
       elseif ($content_type == 'XLS') { ?>
       <img class="align-middle" src="<?php echo get_stylesheet_directory_uri(); ?>/img/xls.png" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="32" height="32" /> <a href="<?php the_field('upload_excel_sheet'); ?>" ><?php the_title(); ?></a>
       }
         <?php 
       }
       ```
   
 * but it won’t show up even if I do another shortcode. Is there a way to add it
   within the shortcode or will it break?

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

 *  Plugin Author [Johann Heyne](https://wordpress.org/support/users/jonua/)
 * (@jonua)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/shortcode-conditional/#post-14389132)
 * Hi nanny7,
 * you can extend the tablefield shortcode as much as you want with more conditionals
   and fields.
 * Cheers,
    Johann
 *  Thread Starter [nanny7](https://wordpress.org/support/users/nanny7/)
 * (@nanny7)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/shortcode-conditional/#post-14414094)
 * Thanks fixed.

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

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

 * ![](https://ps.w.org/advanced-custom-fields-table-field/assets/icon-256x256.png?
   rev=1962986)
 * [Table Field Add-on for ACF and SCF](https://wordpress.org/plugins/advanced-custom-fields-table-field/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-custom-fields-table-field/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-custom-fields-table-field/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [nanny7](https://wordpress.org/support/users/nanny7/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/shortcode-conditional/#post-14414094)
 * Status: resolved