Forum

Thread tagged as: Problem

Debugging perch_content_custom()

Hi guys

We have a page at results.php which has a repeating region called Results (and data stored within it). When trying to pull that data out onto index.php, we get no output. Is there a way to debug it? It all seems to be in line with the docs:

<?php perch_content_custom('Results', array(
    'page' => '/results.php',
    'template' => 'result.html',
    'sort' => 'date',
    'sort-order' => 'DESC',
    'count' => 2
)); ?>

Thanks

Russell Back

Russell Back 2 points

  • 7 years ago

You could add <perch:showall /> to your template which would output all the available content, or alternatively you could turn on debug by adding define('PERCH_DEBUG', true); to perch/config/config.php and <?php PerchUtil::output_debug(); ?> in your index.php file.

That might point you in the right direction to find the issue!

Thanks, that gives me a couple of things:

SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Results' AND (regionPage='/results.php' OR regionPage='*')

Results in:

regionID: 27
regionTemplate: result.html
regionPage: /results.php
rev: 3

So far so good, then this:

SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx 
JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID
JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='date' WHERE ((idx.regionID='27' AND idx.itemRev='3')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev
) as tbl GROUP BY itemID ORDER BY sortval DESC LIMIT 0, 2

Returns no results. Any idea why?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You're sorting by a field with an ID of date - does that exist in your template?

Ah right, no. I'd taken that from the example and assumed that it was pulling from a native date field linked to the date of the entry. Presumably then, to sort region content by entry date (i.e. newest first) we'd need to have the author enter a date as a content field?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's right. But a date field will automatically populate to the current date, so they don't actually need to do anything.

Great, thanks.