Search
Other Articles Anywhere questions
Forum

Custom fields calculation.

Vito Pajič's Avatar Vito Pajič
Hello.

I'am using
- Articles Anywhere
- Snippets
- Sourcerer

I have few custom fields that I am using for the same article category.
I would like to do math with some of the custom fields (+, -, *, /).
I am trying to do that with sourcerer with PHP but It doesn't work.
{source}<?php $a= "{article}[field1:value]{/article}";
$b= "{article}[field2:value]{/article}";

$c = $a + $b;

echo $c;
?>{/source}

this doesn'work.... I also try convert string to number
www.squash.io/how-to-convert-a-string-to-a-number-in-php/
but it also doesn't work...

Any idea how to calcualte with custom field values?

Please help
Peter van Westen's Avatar Peter van Westen ADMIN
It is probably due to the system plugin ordering. Try changing the ordering of the plugins in question.
See: regularlabs.com/blog/242-plugin-order-is-important
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
I don't think that here is problem with plugin order...
I don't have cache enabled.
Peter van Westen's Avatar Peter van Westen ADMIN
It is not about cache.
Articles Anywhere should be ordered before Sourcerer.
Read this again:
regularlabs.com/blog/242-plugin-order-is-important
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
I have put Articles Anywhere to the first but result is the same:

Here is the result when I try to calculate custom field value
0 - Unsupported operand types: string + string
Peter van Westen's Avatar Peter van Westen ADMIN
{source}<?php $a= (int) "{article}[field1:value]{/article}";
$b= (int) "{article}[field2:value]{/article}";

$c = $a + $b;

echo $c;
?>{/source}
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
I try this but then I get 0.

Output echo $a -> I get a = 0;
Output echo $b -> I get b = 0;
and c is also 0;


If I echo "{article}[field1:value]{/article}" then I get 2008 (number).
But I can't get string to int (number) to make calculations...
Peter van Westen's Avatar Peter van Westen ADMIN
What does this output?
{source}<?php 
$a = "{article}[field1:value]{/article}XXX";
echo $a[0];
?>{/source}
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
output a[0] is {

output a[1] is a
output a[2] is r
output a[3] is t
output a[4] is i

as it seams output of area would be {article}[field1:value]{/article}XXX
Peter van Westen's Avatar Peter van Westen ADMIN
So that means that it looks like the ordering of the system plugins is not correct.
Again: check that Articles Anywhere is ordered above/before Sourcerer.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
Oh, this is probably it:
Switch off the option "Disable in Sourcerer" in the Articles Anywhere system plugin settings.
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
Disable in Sourcerer - was on "Yes"
now I put it to "No" and the result is the same :\
Peter van Westen's Avatar Peter van Westen ADMIN
{article}{source}<?php $a= "[field1:value]";
$b= "[field2:value]";

$c = $a + $b;

echo $c;
?>{/source}{/article}

And like that?
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
same...

echo $a[0] is [

plugin setting in System - Regular Labs - Articles Anywhere - Disable in Sourcerer Yes and No - result is the same...
Peter van Westen's Avatar Peter van Westen ADMIN
Can you give me (super) admin and (s)ftp access so I can take a look?
And tell me on what url I can see/reproduce the issue.
You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
I am sending you login data
Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
The admin login doesn't work.
The ftp connection times out.
And what is the url to the article where you have the Sourcerer/Articles Anywhere code?
Please post a rating at the Joomla! Extensions Directory
Vito Pajič's Avatar Vito Pajič
I have corrected link and I try using VPN (Netherlends) and admin should work but ftp won't. My hosting provider is blocking other countries for ftp. At the momemnt I can't change settings for that.
Vito Pajič's Avatar Vito Pajič
FTP should also work for other It must be used port as I have corrected in logins data
Peter van Westen's Avatar Peter van Westen ADMIN
I reordered the system plugins again by draging something to the bottom and top again.
Then went to the Articles Anywhere system plugin settings and saw that the "Disable in Sourcerer" option was enabled.
I switched that off and saved the plugin.
All is working now.
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription