• Resolved dancappdesign

    (@dancappdesign)


    Hi. I want the user to be able to select no tablepress table if he wishes, but when the field is left empty (i.e. with ‘- Select -‘) as the choice, on the front end it displays:

    [table “null” not found /]

    This would be okay, as I am using an if-statement to only display the field if it has a value, but even after putting it inside an if-statement, the frontend still prints “[table “null” not found /]”.

    I’m surprised I couldn’t find any information about this problem already. Surely someone else has already encountered it?

    Thanks in advance.
    Dan

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor pwtyler

    (@pwtyler)

    Hi Dan—

    Sorry for the belated response, I just saw this, I’ll take a look and get back asap!

    best,
    Phil

    Plugin Contributor pwtyler

    (@pwtyler)

    Hi Dan—

    It seems like get_field (or whatever you are using in the template) is returning a literal string of ‘null’, which I’ve actually not been able to replicate. When I do not choose a table in the dropdown, and use the following code in my template,

    $tablepress_id = get_field( 'tp' );
    $args =[ 'id' => $tablepress_id ];
    if ( function_exists( 'tablepress_print_table' ) ) {
      tablepress_print_table( $args );
    }

    I see on the front-end [table “” not found /], which I would say is to be expected. My guess is, you will want to amend the if statement you wrapped the display part of the code to also check that $tablepress_id does not equal ‘null’, something like

    $tablepress_id = get_field( 'tp' );
    if ( ! empty( $tablepress_id ) && $tablepress_id != 'null' ) {
        $args =[ 'id' => $tablepress_id ];
        if ( function_exists( 'tablepress_print_table' ) ) {
          tablepress_print_table( $args );
        }
    }

    I’m sorry I don’t have a better explanation as to WHY it’s happening, but could you tell me exactly what code you are using in your template, and what version of ACF you are using? I tried both ACF 4 and 5, but neither returned a literal ‘null’ string like you’re getting.

    Thread Starter dancappdesign

    (@dancappdesign)

    Thanks for your attention and help. I did actually manage to solve the problem eventually by using the following code:

    <?php 
    $section = get_field('custom_field');
    if ($section != "null") :
    ?>
      <?php
      $table = get_field('my_table');
      if ($table != "null") {
      echo do_shortcode( '[table id="'. get_field('my_table') .'" /]' );
      } ?> 
    <?php endif; ?>
    • This reply was modified 6 years, 11 months ago by dancappdesign.
    • This reply was modified 6 years, 11 months ago by dancappdesign. Reason: Code quote formatting
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[table “null” not found /]’ is closed to new replies.