We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum


Thread tagged as: Question

Accessing a field directly in PHP

I use PHP includes for my headers and footers, and I'm currently defining the <title> tag like this:

In page.php: <? define('PERCH_TITLE',perch_pages_title(true)); ?> In header.php: <title><?echo PERCH_TITLE;?></title>

I have a "gallery" of sorts that is pulling items based on slugs to display, like this:

$slug = $_GET["w"];
$opts = array(
perch_content_custom("Wedding Items", $opts);

How can I access the "title" field inside the filtered item directly for the define('PERCH_TITLE')?


Shane Lenzen

Shane Lenzen 18 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Like this:

$result = perch_content_custom("Wedding Items", array(
    'skip-template' => true,
    'return-html' => true,
echo $result['html'];
$title = $result[0]['title'];

I'd advise against prefixing your own constants with PERCH_ - we do that to avoid conflicts. If you use our prefix, you reintroduce the possibility of those conflicts.

Awesome! I had no idea about echo $result['html'];, I can see that coming in handy in a lot of cases.

Thanks for the advice on constants.