Forum

Thread tagged as: Question, Runway, Blog

Blog Post on Home Page Breaks When postStatus = Draft

Hi all

Using Runway and Perch Blog, I am displaying the latest blog post on the home page using the following...

    perch_blog_custom(array(
        'filter'   => 'postDateTime',
        'match' => 'gte',
        'value' => date('Y-m-d'),
        'sort'  => 'postDateTime',
        'sort-order' => 'DESC',
        'count' => 1,
        'template' => 'blog/home_page.html'
    ));

...which in itself all works absoultely fine.

The problem occurs when the latest blog post status is set to draft. When this occurs the template breaks.

How do I display not only the latest blog post but the latest post that's also got a post status of Published only, please?

Many thanks

Glen Piggott

Glen Piggott 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you mean by breaks?

The template blog/home_page.html doesn't display at all if the latest blog post is set to draft. If you view source it's not there.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does debug output?

This is what the debug looks like when the latest blog is set to Published...

Using template: /templates/blog/home_page.html
[1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
[4] SELECT DISTINCT e.* FROM perch2_events e WHERE eventDateTime>'2016-12-22' ORDER BY eventDateTime ASC LIMIT 4

and this when the latest blog post is set to draft...

Using template: /templates/blog/home_page.html
[4] SELECT DISTINCT e.* FROM perch2_events e WHERE eventDateTime>'2016-12-22' ORDER BY eventDateTime ASC LIMIT 4
Drew McLellan

Drew McLellan 2638 points
Perch Support

Neither of those match the code you're showing me above.

Which bit of the debug do you need?

The above was taken from the frontend home page & I just copied the part which referred to the template in question.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It would save a lot of back and forth if you posted all of it.

Here you go Drew. This is what I get on the home page when the latest blog post status is set to Draft...

Debug Message
[14] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
Matched page: /, so not using routes.
Using master page: /templates/pages/home.php
[1] SELECT * FROM perch2_pages WHERE pagePath='/' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=206
[1] SELECT * FROM perch2_shop_cart WHERE cartID=206
Using template: /templates/pages/attributes/seo.html
Template file not found: /home/sandapple/A4GK83G6/htdocs/cms/templates/pages/attributes/facebook.html
Template file not found: /home/sandapple/A4GK83G6/htdocs/cms/templates/pages/attributes/twitter.html
[7] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='bestSeller' AND idx.indexValue='true')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[38] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/shop/best_seller.html
[2] SELECT productID, productVariantDesc, stock_level FROM perch2_shop_products WHERE parentID=16 AND productDeleted IS NULL ORDER BY productOrder ASC
[1] SELECT o.* FROM perch2_shop_options o, perch2_shop_product_options po WHERE o.optionID=po.optionID AND po.productID=16 AND o.optionDeleted IS NULL ORDER BY optionPrecendence ASC
[3] SELECT valueID AS id, valueTitle AS title, valueSKUCode AS skucode FROM perch2_shop_option_values WHERE optionID=1 AND valueDeleted IS NULL ORDER BY valueOrder ASC
[2] SELECT pov.prodoptID, pov.optionID, pov.valueID, o.optionTitle, ov.* FROM perch2_shop_product_option_values pov, perch2_shop_options o, perch2_shop_option_values ov WHERE pov.productID='16' AND pov.optionID=o.optionID AND pov.valueID=ov.valueID AND o.optionDeleted IS NULL AND ov.valueDeleted IS NULL AND o.optionID='1' ORDER BY o.optionPrecendence ASC, ov.valueOrder ASC
[1] SELECT * FROM perch2_categories ORDER BY catTreePosition ASC
[1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='featured' AND idx.indexValue='true')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[1] Using template: /templates/shop/featured_products.html
[2] SELECT productID, productVariantDesc, stock_level FROM perch2_shop_products WHERE parentID=1 AND productDeleted IS NULL ORDER BY productOrder ASC
[1] SELECT o.* FROM perch2_shop_options o, perch2_shop_product_options po WHERE o.optionID=po.optionID AND po.productID=1 AND o.optionDeleted IS NULL ORDER BY optionPrecendence ASC
[3] SELECT valueID AS id, valueTitle AS title, valueSKUCode AS skucode FROM perch2_shop_option_values WHERE optionID=1 AND valueDeleted IS NULL ORDER BY valueOrder ASC
[2] SELECT pov.prodoptID, pov.optionID, pov.valueID, o.optionTitle, ov.* FROM perch2_shop_product_option_values pov, perch2_shop_options o, perch2_shop_option_values ov WHERE pov.productID='1' AND pov.optionID=o.optionID AND pov.valueID=ov.valueID AND o.optionDeleted IS NULL AND ov.valueDeleted IS NULL AND o.optionID='1' ORDER BY o.optionPrecendence ASC, ov.valueOrder ASC
[1] SELECT * FROM perch2_categories ORDER BY catTreePosition ASC
[1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='testHome' AND idx.indexValue='true')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[1] Using template: /templates/shop/testimonials.html
[2] SELECT productID, productVariantDesc, stock_level FROM perch2_shop_products WHERE parentID=1 AND productDeleted IS NULL ORDER BY productOrder ASC
[1] SELECT o.* FROM perch2_shop_options o, perch2_shop_product_options po WHERE o.optionID=po.optionID AND po.productID=1 AND o.optionDeleted IS NULL ORDER BY optionPrecendence ASC
[3] SELECT valueID AS id, valueTitle AS title, valueSKUCode AS skucode FROM perch2_shop_option_values WHERE optionID=1 AND valueDeleted IS NULL ORDER BY valueOrder ASC
[2] SELECT pov.prodoptID, pov.optionID, pov.valueID, o.optionTitle, ov.* FROM perch2_shop_product_option_values pov, perch2_shop_options o, perch2_shop_option_values ov WHERE pov.productID='1' AND pov.optionID=o.optionID AND pov.valueID=ov.valueID AND o.optionDeleted IS NULL AND ov.valueDeleted IS NULL AND o.optionID='1' ORDER BY o.optionPrecendence ASC, ov.valueOrder ASC
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' WHERE 1=1 AND ((idx.indexKey='postDateTime' AND idx.indexValue >= '2016-12-22')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-12-22 15:20:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 1
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/home_page.html
[4] SELECT DISTINCT e.* FROM perch2_events e WHERE eventDateTime>'2016-12-22' ORDER BY eventDateTime ASC LIMIT 4
[4] Using template: /templates/events/listing/home_page.html
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='4'
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='5'
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='7'
[nil] SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='6'
Request time: 0.1157
Process time: 0.1141
Memory: 6.6406
Drew McLellan

Drew McLellan 2638 points
Perch Support

Your filter is targeting posts with a date greater than the current time, and the default filtering targets posts in the past, so you've only got a very narrow window to match any posts.