Forum

Thread tagged as: Problem, Blog

Perch Blog Custom Multi Filter

Hi there,

Does Perch Blog work with multiple filters like perch_content_custom?

I'm trying this, it's not returning a result when using both filters, but using just one of them works.

<?php
            $year = perch_get('year');
            $dateFrom = $year.'-01-01';
            $dateTo = $year.'-12-31';
            perch_blog_custom(array(
                'filter'=> array (
                    array (
                        'filter' => 'postDateTime',
                        'match' => 'eqbetween',
                        'value' => $dateFrom.','.$dateTo
                    ),
                    array (
                        'filter' => 'postSlug',
                        'match' => 'eq',
                        'value' => perch_get('s')
                    )
                )
            ));
        ?>
Dexter Harrison

Dexter Harrison 29 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, do you get any errors output?

I get this:

Time    Δ  Debug Message
0.194   0   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
0.2061  0.0121  Matched route: blog/[year:year]/[slug:s]
0.2062  0.0002  Using master page: /templates/pages/blog/post.php
0.2063  0   Page arguments:
Array
(
    [0] => /blog/2015/day-three-bett-2015
    [year] => 2015
    [1] => 2015
    [s] => day-three-bett-2015
    [2] => day-three-bett-2015
)
0.2072  0.0009  SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2015-02-28 16:41:00' AND postSlug='day-three-bett-2015'
0.2104  0.0032  SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.2133  0.0029  Using template: /templates/blog/post.html
0.2143  0.0011  Using template: /templates/blog/post.html
0.2153  0.0009  Using template: /templates/blog/post.html
0.216   0.0008  SELECT * FROM perch2_pages WHERE pagePath='/blog/post' LIMIT 1
0.2164  0.0004  Using template: /templates/pages/attributes/default.html
0.2166  0.0002  Using sub-template: /templates/pages/attributes/facebook.html
0.2166  0.0001  Using sub-template: /templates/pages/attributes/twitter.html
0.2275  0.0109  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='postDateTime' AND (idx.indexValue >= '2015-01-01' AND idx.indexValue <= '2015-12-31')) OR (idx.indexKey='postSlug' AND idx.indexValue='day-three-bett-2015')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2015-02-28 16:41:00' ) GROUP BY itemID HAVING count(*)=2 ORDER BY sortval ASC LIMIT 0, 10
0.2406  0.0131  SELECT FOUND_ROWS() AS `count`
0.2414  0.0008  Using template: /templates/blog/post.html

and this

Time    Δ  Debug Message
0.194   0   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
0.2061  0.0121  Matched route: blog/[year:year]/[slug:s]
0.2062  0.0002  Using master page: /templates/pages/blog/post.php
0.2063  0   Page arguments:
Array
(
    [0] => /blog/2015/day-three-bett-2015
    [year] => 2015
    [1] => 2015
    [s] => day-three-bett-2015
    [2] => day-three-bett-2015
)
0.2072  0.0009  SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2015-02-28 16:41:00' AND postSlug='day-three-bett-2015'
0.2104  0.0032  SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.2133  0.0029  Using template: /templates/blog/post.html
0.2143  0.0011  Using template: /templates/blog/post.html
0.2153  0.0009  Using template: /templates/blog/post.html
0.216   0.0008  SELECT * FROM perch2_pages WHERE pagePath='/blog/post' LIMIT 1
0.2164  0.0004  Using template: /templates/pages/attributes/default.html
0.2166  0.0002  Using sub-template: /templates/pages/attributes/facebook.html
0.2166  0.0001  Using sub-template: /templates/pages/attributes/twitter.html
0.2275  0.0109  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='postDateTime' AND (idx.indexValue >= '2015-01-01' AND idx.indexValue <= '2015-12-31')) OR (idx.indexKey='postSlug' AND idx.indexValue='day-three-bett-2015')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2015-02-28 16:41:00' ) GROUP BY itemID HAVING count(*)=2 ORDER BY sortval ASC LIMIT 0, 10
0.2406  0.0131  SELECT FOUND_ROWS() AS `count`
0.2414  0.0008  Using template: /templates/blog/post.html
0.2429  0.0015  SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Notices' AND (regionPage='/blog/post' OR regionPage='*')
0.2433  0.0004  No matching content regions found. Check region name (Notices) and page path options.
0.2434  0.0001  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='message' WHERE idx.regionID IS NULL AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY RAND() LIMIT 0, 1
0.2444  0.001   Using template: /templates/content/
0.2452  0.0008  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.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2015-02-28 16:41:00' ) GROUP BY itemID ORDER BY sortval DESC LIMIT 0, 5
0.4395  0.1943  SELECT FOUND_ROWS() AS `count`
0.4399  0.0004  Using template: /templates/blog/footer.html
0.4479  0.008   Using template: /templates/mailchimp/subscribe.html
0.4552  0.0073  Time: 0.4552
0.4553  0   Memory: 5.4803
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you run the query directly, do you get any results?

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='postDateTime' AND (idx.indexValue >= '2015-01-01' AND idx.indexValue <= '2015-12-31')) OR (idx.indexKey='postSlug' AND idx.indexValue='day-three-bett-2015')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2015-02-28 16:41:00' ) GROUP BY itemID HAVING count(*)=2 ORDER BY sortval ASC LIMIT 0, 10

No, no results.

It's weird, there should be a post that equals that slug and in 2015.

If I run the slug filter on it's own it returns the correct post.

If i run the 2015 one it obviously returns all posts from 2015 including the one that i need.

Drew McLellan

Drew McLellan 2638 points
Perch Support

To confirm, you're using the latest version of Blog (at least as of yesterday), correct?

That's correct.

4.5.4

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you try with today's build just in case?

Absolutely, I'm excited for Blocks anyway.

I'll update now

Updated, no change.

Ran the query too

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, in which case I have no quick answer. I'll have to schedule some time to investigate.

Ok, thanks for your help

Unfortunately, this still seems to be an issue.