• Resolved isaki

    (@isaki)


    Hi,
    Thanks for a great plugin!

    Question:
    Is there any way to know if the filter returns an empty result (doesn’t find anything) ?
    I filter dynamically like this:
    do_shortcode('[table id='.$category_id.' hide_columns="2-5" filter="'.$passtitle.'||'.$sday.'"]');

    And event though nothing is found, some html is still returned/printed. In this example the data from row 1 and column 1.
    Can I avoid that, maybe using a function-call ?

    Best regards
    Isak

    https://wordpress.org/plugins/tablepress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    My suggestion here would be to do some post processing on the string with the HTML that you get from the do_shortcode() call (which you don’t even need, as you could directly call the handler):

    $table_html = tablepress_get_table( array(
      'id' => $category_id,
      'hide_columns' => '2-5',
      'filter' => $passtitle . '||' . $sday,
    ) );

    You could then count how often a certain HTML tag string (like <tr) occurs in that HTML (with the PHP substr_count() function). From that, you know if only the first row/first column was printed. You can then react to that and not echo anything at all.

    Regards,
    Tobias

    Thread Starter isaki

    (@isaki)

    Thank you very much! Worked perfectly.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Find out if filter return empty/nothing’ is closed to new replies.