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

Forum

Thread tagged as: Question, Problem

Content from another page

I'm trying to grab 2 items (car listings) at random from another page (car sales page) multi item perch content field.

I've been on and off trying to get this to work for a week now and I'm not able to play ball, and ideally I don't want to use a shared field as thats confusing for the client adding data in the admin

Can anyone help me see what I'm doing wrong

Thanks

Here's the code on the homepage...

<?php 
perch_content_custom('Vehicle for Sale', array(
'page'=>'/car-sales/index.php',
'template'=>'cars.html',
'sort'=>'date',
'sort-order'=>'RAND',
'count'=>2,
));
?>
Stephen Wild

Stephen Wild 3 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What result are you getting? You've not said.

no results shown and no errors

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does debug output?

Debug Message - Perch 3.0.4
[1] SELECT * FROM perch3_pages WHERE pagePath='/index.php' LIMIT 1
Using template: /templates/pages/attributes/seo.html
[6] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/index.php' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch3_content_regions WHERE regionKey='Banner Image' AND (regionPage='/index.php' OR regionPage='*')
[1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch3_content_index idx JOIN perch3_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch3_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_id' WHERE ((idx.regionID=2 AND idx.itemRev=1)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval, regionID ORDER BY RAND()
[1] Using template: /templates/content/banner_image.html
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch3_content_regions WHERE regionKey='Vehicle for Sale' AND (regionPage='/car-sales/index.php' OR regionPage='*')
[nil] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch3_content_index idx JOIN perch3_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch3_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='date' WHERE ((idx.regionID=10 AND idx.itemRev=26)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval, regionID ORDER BY RAND() LIMIT 0, 2
Using template: /templates/content/cars.html
[11] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
Drew McLellan

Drew McLellan 2638 points
Perch Support

I can't see your Vehicle for Sale region being queried there at all. Are you sure you're on the right page?

Using template: /templates/content/cars.html
[11] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0

Sorry didn't put the debug code after the content

Ok i've now fixed it... feel like a tool

<?php 
perch_content_custom('Vehicle for Sale', array(
'page'=>'/car-sales/index.php',
'template'=>'cars.html',
'sort'=>'_id',
'sort-order'=>'RAND',
'count'=>2,
));
 ?>

Changed

'sort'=>'date',

to

'sort'=>'_id',

Thanks for getting back to me