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, Configuration

Not filtering by category

I am still having problems showing a lists of related posts on post.php (category related). I am using Clive Walker's method that Simon Clay told me, but is not working for me:

//Get the categories for the current post 
$categories = perch_blog_post_categories(perch_get('s'), array(
    'skip-template' => true, ));

//The post may be in more than one category, so we need to loop through these and get the category slugs
if (count($categories)) {
    $cat_slugs = array();
    foreach($categories as $cat) {
        $cat_slugs[] = $cat['catSlug'];
    }

    //Display two related posts, ordered by date, excluding the current post
    perch_blog_custom(array(

        'category' => $cat_slugs, // it show all if i remove this line
        'sort' => 'postDateTime',
        'sort-order' => 'DESC',
        'count' => 2000,
        'template' => 'proyectos.html',
    ));
}

Debug:

Debug Message - Perch 3.0.4
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_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='bbb')) 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-05-30 13:12:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[24] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
[1] Using template: /templates/blog/slug2.html
[1] SELECT * FROM perch3_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch3_blogs ORDER BY blogTitle ASC
[45] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/proyecto.php' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_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='bbb')) 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-05-30 13:12:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /templates/blog/post.html
[3] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_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, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2017-05-30 13:12:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 10000
[1] SELECT FOUND_ROWS() AS `count`
[3] Using template: /templates/blog/proyectos.html
Array
(
    [type] => 8
    [message] => Use of undefined constant perch_blog - assumed 'perch_blog'
    [file] => /Applications/MAMP/htdocs/optaarquitectos.com/perch/config/apps.php
    [line] => 3
)

Diagnostics

Perch: 3.0.5, PHP: 5.4.4, MySQL: 5.5.25, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.5), assets (3.0.5), categories (3.0.5), perch_blog (5.5.1)
App runtimes: <?php $apps_list = [ perch_blog, ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Applications/MAMP/htdocs/optaarquitectos.com/perch
PERCH_CORE: /Applications/MAMP/htdocs/optaarquitectos.com/perch/core
PERCH_RESFILEPATH: /Applications/MAMP/htdocs/optaarquitectos.com/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 64M, Total max file upload: 32M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: opta2:8888
DOCUMENT_ROOT: /Applications/MAMP/htdocs/optaarquitectos.com
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Any help?

Raul Serrano

Raul Serrano 0 points

  • 1 year ago
Drew McLellan

Drew McLellan 2637 points
Perch Support

Have you checked the value of $cat_slugs ?

On debug: Undefined variable: cat_slugs

Drew McLellan

Drew McLellan 2637 points
Perch Support

So if (count($categories)) must be false and therefore you need to see why $categories isn't populated.

Any idea how can I test that? Here is my categories code on post template. Each posts have one category selected

<perch:categories id="categorias_proyectos" label="Categoria" set="proyectos" required="true" suppress="true" divider-before="Categoria" help="Seleccionar solo una categoría">
        <perch:before>
            <ul>
        </perch:before>
        <li>
            <a href="/category/<perch:category id='catPath' />">
                <perch:category id="catTitle" />
            </a>
        </li>
        <perch:after>
            </ul>
        </perch:after>
    </perch:categories>
Drew McLellan

Drew McLellan 2637 points
Perch Support

You need to look at see what the value of $categories is.

When I print_r($categories); it gives me just Array ( )

Drew McLellan

Drew McLellan 2637 points
Perch Support

So it's your perch_blog_post_categories() call.

Should I do something else but this?

$categories = perch_blog_post_categories(perch_get('s'), array(
                             'skip-template'=>true, ));
Drew McLellan

Drew McLellan 2637 points
Perch Support

Maybe. What does this output?

perch_blog_post_categories(perch_get('s'));

It output all posts (no category filtering)

Drew McLellan

Drew McLellan 2637 points
Perch Support

perch_blog_post_categories() outputs categories for a post.

I know, but is not outputing any category... what could I try to see whats happening? Categories are running fine, post is running fine, but that function is not outputting post's categories...

Drew McLellan

Drew McLellan 2637 points
Perch Support

How many categories is the bbb post in?

Only one, and that's the way all posts are going to be

Drew McLellan

Drew McLellan 2637 points
Perch Support

Are they in the default blog category set?

no, they are on a new set called proyectos

Drew McLellan

Drew McLellan 2637 points
Perch Support

Right. I've not idea if that would work then.

Not working... I pass all categories to blog set and is not working.

Is right categories code on post.html?

<perch:categories id="categorias_proyectos" label="Categoria" set="blog" required="true" suppress="true" divider-before="Categoria" help="Seleccionar solo una categoría">
        <perch:before>
            <ul>
        </perch:before>
        <li>
            <a href="/category/<perch:category id='catPath' />">
                <perch:category id="catTitle" />
            </a>
        </li>
        <perch:after>
            </ul>
        </perch:after>
    </perch:categories>

I need to get this working...

Drew McLellan

Drew McLellan 2637 points
Perch Support

What result are you getting?

Same result...