WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Bloggorus
    Member
    Posted 1 year 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 1 year 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 1 year ago #

    thanks tobias, no rush :)

  4. TobiasBg
    Member
    Plugin Author

    Posted 1 year 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 1 year 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 1 year 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 1 year 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 year 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 year 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

  10. jaymccormick
    Member
    Posted 12 months ago #

    Tobias,

    Just wondering if I could some use a global variable on ONE page - associated with an href - to call another page that contained the actual TablePress table, as use the filter extension with a variable in it to then show the table only with that filter results. Basically click on a link or button that says 'blah' on it, then open another wordpress page with a tablepress table in it that only displays rows that say 'blah'. Sounds simple, but fairly new to wordpress. I am voluntering for a non-profit to assist them.

    Can you tell me simply or direct me to an article or how-to on that? Thanks.

  11. TobiasBg
    Member
    Plugin Author

    Posted 12 months ago #

    Hi,

    thanks for your question.

    This sounds like a perfect scenario for the TablePress Row Filter Extension from http://tablepress.org/extensions/row-filter/ in conjunction with the Extension https://tablepress.org/extensions/shortcode-filter-get-parameter/

    Regards,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.