In researching this further, I ran across your Tablepress Extension for accessing individual table cells. I will play with that a bit, and update this thread with the results.
Extension can be found here: https://tablepress.org/extensions/table-cell-shortcode/
Hi,
thanks for your question, and sorry for the trouble.
Yes, that TablePress Extension is indeed the best solution here. Good to hear that you already found it!
Regards,
Tobias
Hi.
The TablePress extension pulls the data out just great!
I could use some pointers however. I would like to be able to send in the ID as a variable, so that I can reuse the shortcode on different event pages.
ie: [table-cell id=xx cell=H2 /], where the xx would be sent in depending upon the table I need to reference.
Thanks in advance for the pointers. I’ve been slogging through support forums all day, and just keep finding things that don’t seem to work.
Regards,
Kathy
Hi Kathy,
unfortunately, I’m not aware of a direct solution for that. Shortcodes don’t have a concept of variables by default. So, you’d probably have to write custom code that basically wraps the Shortcode with some custom handling, where the ID is retrieved from your variable and then passed through to the Shortcode handler.
Regards,
Tobias
Hi Tobias,
I was wondering about that – so thanks for the push that direction. I wrote a function which will now pull a variable directly from a table cell, using your TablePress Extension shortcode. Works like a charm!
For others who might run into this, here is what I did. I suspect there are more elegant solutions out there, but this works for me.
Create a function that first finds the tablepress ID for the table I want to reference.
Then, create a string that represents the shortcode to be run, adding in the tablepress ID in the midst, and return that value.
Lastly, create a variable that is assigned this new shortcode string. Use the variable where the shortcode would be used.
function nameofthishike_get_var()
{
global $my_nameofthishike_var;
$my_tablecellid_var=tablepressid_get_var();
$my_hike_shortcode_var=sprintf(“[table-cell id=”.$my_tablecellid_var.” cell=H2/]”);
$my_nameofthishike_var=sprintf($my_hike_shortcode_var);
return $my_nameofthishike_var;
}
<?php $nameofthishike=nameofthishike_get_var();?>
Hi,
very nice! Good to hear that you were able to extend this so that it uses your variable!
Best wishes,
Tobias
P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!
Hi, Tobias, I am using the table cell shortcode extension to pull in a value from another table that I want to apply a few calculations on, e.g.;
Cell A2 : Value from another table (this value pulls through nicely)
Cell B2 = A2*0.03
Cell C2 = A2*0.06
Cell D2 = A2+B2+C2
However, I get the following error in cells B2, C2 and D2: !ERROR! A2 does not contain a number or expression.
What am I doing wrong?
-
This reply was modified 8 years, 2 months ago by
gerhardjvr.
Hi,
thanks for your post, and sorry for the trouble.
For this, you will need the TablePress Shortcodes before Formulas Extension, from https://tablepress.org/extensions/shortcodes-before-formulas/
After installing and activating it, modify the Shortcode that you use with an extra parameter:
[table id=1 shortcodes_before_formulas=true /]
Regards,
Tobias
Wow! that was quick… Thank you so much.
Apologies, Tobias, but I’m battling…Where do I use this shortcode? I have 2 tables, let’s call them;
Source: [table id-1 /] – This table has a value in B2 that I pull in to the results table
Results: [table id-3 /] – Cell B2 from the source is pulled into A2. I then have a formula in B2: =A2*0.03, but this cell then gives me the error I mentioned above.
I tried to add the parameter “shortcodes_before_formulas=true” in both tables above, to no avail;
[table id-1 shortcodes_before_formulas=true /]
Can you point me in the right direction, please?
Hi,
you would add the parameter (by modifying the existing Shortcode) on the page where you are displaying the results table 3. Right now, you have
[table id=3 /]
there. That should become
[table id=3 shortcodes_before_formulas=true /]
The parameter will then cause that Shortcodes inside this table 3 will be parsed before the formulas in the table are evaluated.
Regards,
Tobias
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!