Support » Plugin: TablePress » execute shortcode before filter=””

  • Resolved cloudduster

    (@cloudduster)



    hello tobias,

    i have a question. i have a row that looks like this:

    ======> col 1 | col 2
    Row 1 = Rates | 1,000.00
    Row 2 = Time | [run shortcode here] {will show the time or display ’empty’}

    i then use this:

    [table id=123 filter=”empty” filter_columns=”2″ filter_inverse=true /]

    but the problem is:

    the filter executes first before the shortcode, so even if the shortcode results to ’empty’ it will be displayed still.

    is there any workaround with this?

    thanks.

    • This topic was modified 9 months, 3 weeks ago by  cloudduster.
    • This topic was modified 9 months, 3 weeks ago by  cloudduster.
    • This topic was modified 9 months, 3 weeks ago by  cloudduster.
    • This topic was modified 9 months, 3 weeks ago by  cloudduster.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    This is a bit tricky, as Shortcodes only run when the table is rendered, which is after filtering. The only chance that I see would be to run the Shortcodes earlier as well.

    For that, you can try adding this code to your theme’s “functions.php” or to the end of the TablePress Row Filter Extension’s PHP file:

    add_filter( 'tablepress_table_raw_render_data', 'tablepress_cloudduster_shortcodes_early', 9, 2 );
    function tablepress_cloudduster_shortcodes_early( $table, $render_options ) {
    	// Early exit, if no or an empty "filter" parameter is given.
    	if ( empty( $render_options['filter'] ) ) {
    		return $table;
    	}
    
    	for ( $table['data'] as $row_idx => $row ) {
    		for ( $row as $col_idx => $cell ) {
    			$table['data'][ $row_idx ][ $col_idx ] = do_shortcode( $cell );
    		}
    	}
    	return $table;
    }

    Regards,
    Tobias

    tobias you’re the best since day 1. i will try this. thank you.

    can you help me with this?

    syntax error, unexpected ‘as’ (T_AS), expecting ‘;’

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    my bad. The two for loops have to be foreach loops of course!

    Regards,
    Tobias

    perfect! it’s working now.

    this will save me hundreds of hours!

    thanks tobias

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

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

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘execute shortcode before filter=””’ is closed to new replies.