Forums

TablePress
[resolved] Shortcode to call table cell data (9 posts)

  1. Bloggorus
    Member
    Posted 5 months ago #

    I found the shortcode from this WP Table Reloaded thread very useful -->

    http://wordpress.org/support/topic/wp-table-reloaded-can-i-reference-another-cell

    I would like to modify it to work with Tablepress. Is it as simple as updating the global variable to what Tablepress uses?

    Code below, thanks in advance

    <?php
    
    // handle [table_cell id=123 c=4 r=5 /]
    function shortcode_handler_table_cell( $atts ) {
      global $WP_Table_Reloaded_Frontend;  
    
      $atts = shortcode_atts( array( 'id' => 0, 'c' => 0, 'r' => 0 ), $atts );
      $table_id = $atts['id'];
      $column = $atts['c'] - 1; // subtract 1 because of different array index
      $row = $atts['r'] - 1; // subtract 1 because of different array index
    
      $table = $WP_Table_Reloaded_Frontend->load_table( $table_id );
      $cell_content = $table['data'][$row][$column];
      $render = $WP_Table_Reloaded_Frontend->create_class_instance( 'WP_Table_Reloaded_Render', 'render.class.php' );
      return do_shortcode( $render->safe_output( $cell_content ) );
    }
    add_shortcode( 'table_cell', 'shortcode_handler_table_cell' );
    ?>

    http://wordpress.org/extend/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    thanks for your post.

    As this has been asked recently, I will also create an Extension for this over the weekend. Unfortunately, it's not as easy as just replacing the variables, but not that much harder.
    I hope to have it ready early next week.

    Regards,
    Tobias

  3. Bloggorus
    Member
    Posted 5 months ago #

    thanks tobias, no rush :)

  4. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    no problem! :-)
    I have the solution in my head, I just need to write down the code this weekend :-)
    I will post instructions here, then.

    Regards,
    Tobias

  5. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    good news! The Extension is ready :-)

    Just install and activate https://github.com/downloads/TobiasBg/TablePress-Extensions/tablepress-single-cell-shortcode.zip as a regular WordPress plugin.
    After that, you can use the Shortcode

    [table-cell id=123 cell="B5" /]

    to get the content of a single cell (in this case of cell B5 from the table with the ID 123). If you prefer a different syntax, you can use

    [table-cell id=123 column=2 row=5 /]

    to get the same.

    Best wishes,
    Tobias

  6. Bloggorus
    Member
    Posted 5 months ago #

    many thanks tobias, just implemented it and it works perfectly.

    My ultra-simple shopping cart is up and running

  7. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi,

    very nice, thanks for the confirmation! :-)

    Best wishes,
    Tobias

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

  8. rapidx
    Member
    Posted 1 month ago #

    Does this plugin still exist TobiasBg? I am trying to get data from a Tablepress table through php. Is it possible without a shortcode?

  9. TobiasBg
    Member
    Plugin Author

    Posted 1 month ago #

    Hi,

    thanks for your question. Yes, this Extension still exists, it's just no longer directly hosted on GitHub (as GitHub removed that option).
    You can now find it at http://tablepress.org/extensions/table-cell-shortcode/
    The source code should give you ideas about how to access a table with PHP.

    Regards,
    Tobias

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.