Articles Anywhere

Php variable as article filter

4 months 1 week ago #89612

Octav A's Avatar Octav A

Hello,
Please advise if is possible to filter articles like this. This does not work, but i need to filter articles in a custom module (in editor) by php variable:

{source}
<?php
$variable = "some_php_code";
?>
{articles custom_field="<?php echo $variable; ?>"}[title]{/articles}
{/source}

4 months 1 week ago #89613

Peter van Westen's Avatar Peter van Westen Admin

Yes, that is possible. But this is more stable:

{source}<?php
$variable = "some_php_code";
echo '{articles custom_field="' . $variable . '"}[title]{/articles}';
?>{/source}
Also, make sure the Sourcerer plugin is ordered before Articles Anywhere.
See: www.regularlabs.com/guides/242-plugin-order-is-important

4 months 1 week ago #89614

Octav A's Avatar Octav A

All your extensions are so setup and work that articles is ordered first of sourcerer (which is last). If i change i break everything.
Will try something else if only such order is mandatory

4 months 1 week ago #89615

Peter van Westen's Avatar Peter van Westen Admin

You can 'break' the Articles Anywhere syntax so that Articles Anywhere will only see it after Sourcerer has handled the code:

{source}<?php
$variable = "some_php_code";
echo '{' + 'articles custom_field="' . $variable . '"}[title]{' + '/articles}';
?>{/source}
PS: Depending on where you place this code, it can mean that it is handled in the last stage of rendering. Then Articles Anywhere won't have a chance to pick up the tags in the output generated by Sourcerer.

4 months 1 week ago #89616

Octav A's Avatar Octav A

Too complicated this, I will need some time to try. But if you help with this i will dont need to:
Can i use article data as variable inside php. Concretely as part of url to be parsed? Of course - the way i put article tags below does not work.

{source}{article}
<?php
$url = "http://example/[article-custom-field]";
$result = file_get_contents($url);
echo $result;
?>
{/article}
{/source}

4 months 1 week ago #89617

Peter van Westen's Avatar Peter van Westen Admin

Here you would have to make sure Articles Anywhere is ordered before Sourcerer.

I guess you want to output the raw value of the custom field.
Read the docs: www.regularlabs.com/extensions/articlesa...a-tags-custom-fields

4 months 1 week ago #89635

Octav A's Avatar Octav A

Thanks for your time.