• Resolved cesser

    (@cesser)


    Hi there

    I’m wondering if there’s any way to display a random Tablepress table from a pool of tables I’ve created?

    Let’s say, for example, I have 5 tables I’ve created, but I want to only display a random one of those. Is there any way to do that with shortcode?

    Thanks in advance

    Carl

    https://www.ads-software.com/plugins/tablepress/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Carl,

    thanks for your question!

    Unfortunately, I don’t have a readily usable solution for that, but you can write a quick custom wrapper for the regular [table] Shortcode:

    function tablepress_random_table_shortcode( $attributes ) {
    	$table_ids = explode( ',', $attributes['from'] );
    	$attributes['id'] = $table_ids[ array_rand( $table_ids ) ];
    	unset( $attributes['from'] );
    	return tablepress_get_table( $attributes );
    }
    if ( ! is_admin() ) {
    	add_shortcode( 'random-table', 'tablepress_random_table_shortcode' );
    }

    Just paste that into your theme’s “functions.php” or into a small new plugin file.
    After that, you can use a Shortcode like

    [random-table from="1,4,6,7,9" /]

    to show a random table from the set of the tables with the IDs 1, 4, 6, 7, and 9.

    Regards,
    Tobias

    Thread Starter cesser

    (@cesser)

    That totally worked! Thank you SOOOOO much Tobias for taking the time to write that. Above and beyond what I had hoped for. I was pulling my hair out for hours trying to figure out a way to do it. I have sent a donation.

    I really appreciate it – you rock!!

    Carl

    Thread Starter cesser

    (@cesser)

    Resolved.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!
    And thanks for the donation, I really appreciate it!

    Best wishes,
    Tobias

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Any way to display a random table?’ is closed to new replies.