Forum
Best way to return a single field?
Think I may have asked this before but... what is best way of fetching the value of a particular field with perch_content_custom?
I currently do as follows:
$articleData = perch_content_custom('Article',
array(
'page'=>'/article.php',
'skip-template'=>'true'
)
);
$articleAuthor = $articleData[0]['article-author'];
Ah, looks like I may already be doing it 'right':
From https://forum.grabaperch.com/forum/09-03-2014-portfolio-fetching-latest-item-related-items-from-same-category?page=1#reply-4405
I'd like to provide a neater way to do this for quick-hit fields. What's stopping me is:
Devising a syntax that is flexible enough but also non-verbose, and
Making sure that mis-use (as inevitably will happen) doesn't have negative impacts on page performance
Thanks for that insight.
When my mind was wandering, an additional parameter sprang to mind, e.g.
'field'=>'article-author'
...but then what happens if you want multiple fields? Perhaps you then wander into'field'=>array('article-author','article-date')
territory... and it suddenly doesn't feel any neater.On second look, it strikes me that it is possibly as neat as it is going to get - I guess the only thing would be skipping the
[0]
parent array if it only returns a single item... but, again, probably not really worth it.shrug