• Resolved Constantin Flux

    (@constantflux)


    Hi,

    I’m trying to accomplish the following.
    I have pages that get dynamically generated with Elementor and I am filling them with content via ACF. Also, I’m loading tables with TablePress in a different part of the website and it works great. So I have tables in my database and listing them on a dedicated page. Great!

    Now I’d like to use those tables on dynamically generated pages as well.
    But to call them dynamically in context with the page being generated, I’d need a short-code for the tables to call the correct table for the page.
    The short code should contain a function that looks at the page title it is on and then pull the correct table from the database. All tables are called the same name as the pages titles plus the word “table”: “some-title-table”, “another-title-table” etc.
    So in the shortcode the call should be for
    PAGE-TITLE-table

    If a table with the name of PAGE-TITLE exists and has content it should show on the according page.
    So on a page called:
    domain.com/category/some-title

    there should be the table called “some-title-table” visible if the table exists and has content. Otherwise not render the table.

    And for
    domain.com/category/another-title

    there should be the table called “another-title-table” visible if the table exists and has content. Otherwise not render the table.

    I hope I’m making sense here.
    Any ideas on how to set up a function in the backend for such a shortcode?

    Thanks kindly!

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    This should not be too difficult. Essentially, you could define your own wrapper Shortcode:

    add_shortcode( 'tablepress_table_from_title', 'constantflux _tablepress_table_from_title' );
    function constantflux _tablepress_table_from_title( $atts ) {
      $title = sanitize_title_with_dashes( get_the_title() );
      $atts['id'] = "{$title}-table";
      return tablepress_get_table( $atts );
    }

    The generation of the $title variable would have to be adjusted as needed. Then, just add the Shortcode

    [tablepress_table_from_title /]
    

    on those pages.

    Regards,
    Tobias

Viewing 1 replies (of 1 total)
  • The topic ‘Calling table on dynamic page by using page title’ is closed to new replies.