It’s seems I cant get even my own shortcode to display within PressTable content (added to the theme function.php file).
> Created shortcode [example]1[/example] which prints 1.50.
* works inside “page” or “article”.
* unable to get it work inside PressTable content (row).
Hi,
thanks for your post, and sorry for the trouble.
It’s really strange that the Single Cell Shortcode Extension is not working inside a table. Just to be sure: That Extension is activated as a plugin (I’m asking because it’s an easy step to forget)?
Then, for using that Shortcode in formulas, you will need to install a second Extension, to basically swap the order of execution: https://tablepress.org/extensions/shortcodes-before-formulas/
For more information on how to use this, please see these threads:
http://ww.wp.xz.cn/support/topic/shortcode-used-in-cell
and
http://ww.wp.xz.cn/support/topic/calling-other-table-cell-values-from-another-table
To then get the updates as quickly as possible, it’s usually a good idea to also turn off table output caching for the table, by adding another Shortcode parameter:
[table id=123 shortcodes_before_formulas=true cache_table_output=false /]
Regarding your own [example] Shortcode: If you can’t get it to work, what does the code look like for it?
Finally, some side notes: Having over 1,500 product tables should be possible, but it might become hard to manage. In the long run, it might be better to go with a custom shop solution here, for best results and flexibility.
Regards,
Tobias
Hi, thanks for the reply!
First off, my shortcode.
function kaupat( $atts , $content = null ) {
extract( shortcode_atts(array('kauppa' => '0',), $atts ));
$postikulut = array("1.90", "7.50");
echo $postikulut[$content]; }
add_shortcode( 'postikulut', 'kaupat' );
Every TablePress related plugins is activated indeed. I still keep getting !ERROR! illegal character ‘[‘ when trying to use shortcodes.
example: =sum(B2,[postikulut]1[/postikulut])
Article includes [table id=4 shortcodes_before_formulas=true /]
In most simple way, goal is here to get certain row value from the table + shortcode OR from table_1 column B row (something) = output into table row, these changes depending on situation (as in they are not always same row number or column letter).
About looking into other solutions, I did but sadly all the shop related plugins comes with features I dont need (such as shopping cart etc) and they feel bloated, I enjoy doing custom solutions and learning ropes the hard way, which is reason I started looked into coding custom shortcodes.
Anyhow, I will send review with 5 stars for you plugin, it does the job without problems, my skills to modify plugin should not affect star numbers in this case (as you provide tools and help for that).
An update.
I got the orginal problem solved.
=sum(B2, [table-cell id=1 row=1 column=2 /]) works now.
1) but it does not work inside the table editor when previewing. Is there any chance you consider to look into that? Keep getting “!ERROR! illegal character ‘[‘”, alto everytihng works when viewing article itself.
2) Second, since I’m doing price thing, (26.80 + 1.90 as example), results is 28.7, I would need it to keep “currency format”, as in 28.70. It can go 123.19 etc. Is there some trick I can use to preserve right format?
EDIT #2 Another problem solved. Small tweaks to my shortcode allowed me to do everything I wanted and get results displayed with PressTable.
I simply created shortcode
[postikulut kauppa="x" hinta="xxx.xx"] €
kauppa = shipping cost from shop ID listed in array.
hinta = product price.
Shortcode produces
return number_format($postikulut[$kauppa] + $hinta,2);
and ta-daa, I was correct format (xxx.xx) and automatic shipping cost calcutator, yay.
EDIT #1
Problem solved with my own shortcode, I had “echo” instead “return”, it’s now showing as it should. Still wondering about #2 mentioned in previous post.
To make things even better, I added new shortcode for “link title” that I can use, instead pasting same text and worrying if I made a typo somewhere.
Still wondering about #2 mentioned in previous post, but since orginal question is now fixed, for my side at least, I will mark this as solved.
Hi,
yes, Shortcodes must return values, not echo them. Nice find!
For 1) (the Shortcode not working in the Preview): That is expected, as the Shortcode is only available on the frontend, as it’s usually not needed in the admin area. To change that, just remove the line
if ( ! is_admin() )
near the top of the Extension’s PHP file.
For 2):
To keep this a currency, you can embed the formula into a string and use the number_format() function. For details, please see http://tablepress.org/tablepress-features-formulas/
You will basically just have to change the cell content to
=$ {number_format( sum(B2, [table-cell id=1 row=1 column=2 /]), 2 )}
Regards,
Tobias