Forum

Thread tagged as: Problem, Blog

Error with specific blog posts

Hi,

I have a weird issue where 2 blog posts will not display returning empty content.

In my post.php I do

$post = perch_blog_custom(array(
          'filter'        => 'customPostSlug',
          'match'         => 'eq',
          'value'         => perch_get('s'),
          'skip-template' => 'true',
          'return-html'   => 'true',
      ));

and then print it with

<?php echo $post['html']; ?>

When going to the url using the customPostSlug I get 404 while when using the default postSlug I get an empty $post. Here the debug when getting the empty $post. (the "Undefined offset: 0" is because I use $post[0] in post.php)

Debug Message
[28] 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 route: post/[slug:s]
Using master page: /templates/pages/blog/post.php
Page arguments:
Array
(
    [0] => /post/el-color-de-2016
    [s] => el-color-de-2016
    [1] => el-color-de-2016
)
[1] SELECT * FROM perch2_pages WHERE pagePath='/post' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=216
[1] SELECT * FROM perch2_shop_cart WHERE cartID=216
[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='_id' WHERE 1=1 AND ((idx.indexKey='customPostSlug' AND idx.indexValue='el-color-de-2016')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-12-17 19:53:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[38] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using template: /templates/blog/post.html
Using sub-template: /templates/blog/heroe_image.html
[1] 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='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='el-color-de-2016')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-12-17 19:53:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /templates/blog/meta_head.html
[3] SELECT * FROM perch2_blog_authors ORDER BY authorFamilyName, authorGivenName ASC
[1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
[38] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[5] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/post' OR regionPage='*' ORDER BY regionPage DESC
[4] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/post' LIMIT 1
[2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
[4] Using template: /templates/navigation/item.html
Using template: /templates/search/menu_search.html
[1] SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2016-12-17 19:53:00' AND postSlug=''
[nil] SELECT * FROM perch2_blog_comments WHERE 1=1 AND postID=0 AND commentStatus='LIVE' ORDER BY commentDateTime ASC
[] Using template: /templates/blog/comment.html
Fetching from cache: perch_blog_author_for_post8a3f3a0cb5c929c217089ec1e1723148
Cache file not found: perch_blog_author_for_post8a3f3a0cb5c929c217089ec1e1723148
Using template: /templates/mailchimp/forms/subscribe.html
[4] SELECT 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='featured' AND idx.indexValue='si')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-12-17 19:53:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 5
[4] Using template: /templates/blog/post_titles.html
[1] SELECT groupID FROM perch2_navigation WHERE groupSlug='footer-links' 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=2 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=2 AND p.pagePath='/post' LIMIT 1
[2] Using template: /templates/navigation/footer-links.html
Request time: 0,0825
Process time: 0,0811
Memory: 5,6488
Array
(
    [type] => 8
    [message] => Undefined offset: 0
    [file] => /Users/proko/Sites/annaand.co/admin/templates/pages/blog/post.php
    [line] => 29
)

Some notes

  • The two posts with the problem initially had the same title and same postSlag. I changed the titles and even delete one of them and rewrote it with different title and slug but still having the problem.
  • There are around 130 posts, I tried many of them and the problem only appears with these 2

Do you see the problem in my code? What else should I try?

Thanks a lot!!

Proko Mountrichas

Proko Mountrichas 3 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

This is the query that's returning no results:

[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='_id' WHERE 1=1 AND ((idx.indexKey='customPostSlug' AND idx.indexValue='el-color-de-2016')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-12-17 19:53:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10

It's looking for customPostSlug being equal to el-color-de-2016. Does that look right?

Hmm no, "el-color-de-2016" is the default postSlug. So it is ok to look for customPostSlug but the value is not the good one.

Looks like for some reason it replaces the value of customPostSlug with the one from the postSlug?

I had a look at the DB and the values are correct there!

Drew McLellan

Drew McLellan 2638 points
Perch Support

What value is s= on the URL at that point?

perch_get('s'); returns the postSlug instead of the customPostSlug

Drew McLellan

Drew McLellan 2638 points
Perch Support

What is the literal value of s= on your URL?

el-color-de-2016

It should be el-color-Pantone-2016 (the custom slug I set in admin)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so that's what you need to fix. Where in the link being output?

Sorry Drew, I didn't get your last question. What link? Not sure where should I look.

Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you getting that URL?

I never understood how blog routings work. I'm completely confused with this issue. Now when I change the Blog post page path, it has no effect. Anyway I will do more troubleshooting and may come back. Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Before routing - check how you're forming the link to that page.

When saying the link to that page do you mean the url? If so what I'm doing in the post.html is the following

<perch:blog id="customPostSlug" type="slug" label="URL del Post" size="xl autowidth" order="1" editable="true" suppress="true" />

So the user should manually add the url they want for the blog post. This works ok with all posts(I've tested) except the two posts I mentioned in the first comment.

Found that the posts didn't work because one had the character ñ in the customPostSlug and the other had a capital P . However these both are valid for URLs as far as I know. How could I make these characters work?

Update: I changed my template as follows in order to avoid 404s from internal links.

<perch:blog id="customPostSlug" type="slug" for="postUrl" editable="false" suppress="true"/>
<perch:blog id="postUrl" type="text" label="URL del Post" size="xl autowidth" order="1" suppress="true" />

But still I need to include ñ and capital letters in the URLs. The site I'm working on is a redesign and there are links coming to the site using these characters.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's stopping you using those characters?

The slug tag Creates a URL-safe slug from the content of one of the other fields so transforms to lowercase and replaces ñ with n

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you not using a custom slug? If so, you can use whatever characters you like.

If you are asking Perch to generate the slug it will sanitise the content to a more safe, portable form that will work as the site is moved between different servers. (which may or may not have good unicode handling for URLs)

This is why the posts did not work. The special character's give the errors I described initially. Do you mean that my local apache is the problem then?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't understand what problem you're experiencing.

The problem is that when the customPostSlug contains a capital letter or ñ the custom post URL returns a 404.

I have a post with the following fields:

Title: El color del año 2016 (simple text field)

Custom URL: el-color-del-año (<perch:blog id="customPostSlug" type="text" label="whatever" suppress="true" />)

Same happens if customPostSlug has a type of slug.

Now mysite.com/post/el-color-del-año --> 404

mysite.com/post/el-color-del-ano --> OK

For me it's not a blocker anymore since I can find the few existing urls with special characters and 301 them to the "safe" urls. I´d only like to now what the problem is in case there something bigger hidden. Thanks for your time!

Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you rewriting your URLs?