Forum

Thread tagged as: Question, Problem, Blog

Search results outputs from all pages

Hello,

I am trying to only output results from the /blog/[...] pages. This is my code:

                        <?php 
                            $query = perch_get('q');  // 'q' query string argument e.g. search.php?q=apples
                            $opts = array(
                                'count'=>8,
                                'from-path'=>'blog/',
                                'excerpt-chars'=>300,
                                'paginate' => true,
                                'page-links' => true,
                                'page-link-style' => 'all',
                                'cache' => false,
                                );
                            perch_content_search($query, $opts);
                        ?>

My problem is that the results from all pages are being shown.

Mike

Mike Hendriks

Mike Hendriks 0 points

  • 3 weeks ago

Hi Mike

Did you try 'apps' => 'perch_blog' as an option for the search function? I've not used it myself but this might help limit to the blog app.

Jon

Hi Jonathan,

Thanks for the reply, unfortunately it does not work.

Mike

Hussein Al Hammad

Hussein Al Hammad 86 points
Registered Developer

Hello Mike,

If you are looking to narrow the search by path, you would use 'from-path' => '/blog'.

If you are looking to narrow the search by the blog app, you would use 'apps' => ['PerchBlog'].

'from-path' => '/blog' is not working for me, but 'apps' => ['PerchBlog'] does work. Thank you, Hussein.

Drew McLellan

Drew McLellan 2602 points
Perch Support

from-path refers to page content. Blog posts are coming from the Blog app, so you need the apps option there.