Forum

Thread tagged as: Problem, Blog

Blog posts not showing on Home page

Hi Drew,

Since updating to v3 and subsequently the latest version, the blog posts are nolonger being displayed when using the following

php perch_blog_custom([
    'template' => 'promo.html',
    'count' => '3',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',             
    'filter'=>array(
array(
        'filter' => 'postDateTime',
    'match' => 'gte',
    'value' => date('Y-m-d H:i:s', strtotime('- 3 MONTHS')),
        ),
array(
        'filter'=>'promoinc',
        'match'=>'eq',
        'value'=>1,
        ),
)               
]); ?>

I have checked to see when the client last posted and it was a couple of times in May. so there should be atleast 2 out of 3 posts showing.

Any thoughs much appreciated.


Perch: 3.0.8, PHP: 7.0.17, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_blog (5.5.1), perch_forms (1.9), perch_shop_orders (1.2.2), perch_shop_products (1.2.2), perch_shop (1.2.2), perch_comments (1.2.1), perch_members (1.6.2), perch_backup (1.2), perch_mailchimp (3.1), perch_twitter (3.7) App runtimes: <?php $apps_list = array( 'perch_blog', 'perch_comments', 'perch_forms', 'perch_mailchimp', //'perch_twitter', 'perch_members', 'perch_shop', ); PERCH_LOGINPATH: /admin PERCH_PATH: /home/sites/courtneyandco.uk/public_html/admin PERCH_CORE: /home/sites/courtneyandco.uk/public_html/admin/core PERCH_RESFILEPATH: /home/sites/courtneyandco.uk/public_html/admin/resources Image manipulation: GD PHP limits: Max upload 64M, Max POST 8M, Memory: 128M, Total max file upload: 8M F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7 Resource folder writeable: Yes HTTP_HOST: courtneyandco.uk DOCUMENT_ROOT: /home/sites/courtneyandco.uk/public_html/ REQUEST_URI: /admin/core/settings/diagnostics/ SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
Nick Loat

Nick Loat 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does the debug output?

Debug Message - Perch 3.0.8
[1] SELECT * FROM perch2_pages WHERE pagePath='/index.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=6077
[1] SELECT * FROM perch2_shop_cart WHERE cartID=6077
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
[29] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=3 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/index.php' LIMIT 1
[1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-001', '000') ORDER BY pageTreePosition DESC
[6] Using template: /templates/navigation/item.html
[7] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/index.php' OR regionPage='*' ORDER BY regionPage DESC
[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 >= '2017-03-26 11:41:18') OR (idx.indexKey='promoinc' AND idx.indexValue=1)) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2017-06-26 11:41:00' ) GROUP BY itemID, sortval HAVING count(*)=2 ORDER BY sortval DESC LIMIT 0, 3
[1] SELECT FOUND_ROWS() AS `count`
[55] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using template: /templates/blog/promo.html
[1] SELECT groupID FROM perch2_navigation WHERE groupSlug='footer' LIMIT 1
[2] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
[0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/index.php' LIMIT 1
[2] Using template: /templates/navigation/footer.html
Drew McLellan

Drew McLellan 2638 points
Perch Support

The query isn't returning any posts.

What steps have you followed to debug it? Have you broken the request down and tried building it back up?

Hi Drew, Three blog posts are displayed if I strip out the filtering so the issue must be how I've set that up. have I written the filtrer arrays correctly to achieve the intention below?

Display the 3 newest posts (that their "promoinc" field checked OK in the admin) in descending order made in the last three months.

Duncan Revell

Duncan Revell 78 points
Registered Developer

You may be being afflicted by the funny group by issue for multiple filters.

Try this and see if it gives you what you're after:

'filter-mode' => 'ungrouped',

Hi Duncan (Drew),

That's seems to have done the trick! Thank you. I've changed the code in the following way see below… as I'm a designer rather than a programmer is this the correct way of doing this?

<?php perch_blog_custom([
    'template' => 'promo.html',
    'count' => '3',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',             
    'filter'=>array(
        array(
        'filter' => 'postDateTime',
        'filter-mode' => 'ungrouped', 
        'match' => 'gte',
        'value' => date('Y-m-d H:i:s', strtotime('- 3 MONTHS')),
        ),
        array(
        'filter'=>'promoinc',
        'filter-mode' => 'ungrouped', 
        'match'=>'eq',
        'value'=>1,
        ),
    'filter-mode' => 'ungrouped', 
    )
]); ?>  
Duncan Revell

Duncan Revell 78 points
Registered Developer

I think you probably only need the one at the bottom (the last one)

I thought that had fixed it but it hasn't. I'd left in a stripped down perch_blog_custom call without the filtering which works in that it displays items just not necessarily the ones I want.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which version did you upgrade Blog from?

Good question. I'll see if I can figure it out. However I'm pretty good at jumping on new updates so on both sites that this problem is occuring blog would not have been older than 4.5.4 or possible 4.5.3 but most likely it would have been version 4.6

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you logged into Blog did it run through migrating your posts?

Not that I recall

I'm pretty sure that I replaced the core in the normal way, replaced the blog app, uploaded everything, logged into the admin, received the updated noticifcation and that was it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So you've not visited the Blog app in the control panel since updating?

On both sites that are suffering with the same issue, I've visited the blog app, primarily to check that the last post was within the last 3 months (as that was my initial thought as to why nothing was showing.) I don't recall seeing it/or being told that it was migrating my posts. I haven't tried adding a new post, would that automatically be in the right "format" (i.e. not need migrating)? If so I'll happily create new posts to replace the old ones.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Both sites? Are they on the same server?

I'll check

They are on separate servers.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the code the same on both? I'm confused what we're dealing with now.

Sorry Drew… Yes, I reused it on another site, as I thought it was pretty cool.