I have a function which is searching through my posts to find a certain category:
$thisCatsPosts = $allPosts->findby('category', 'category-one');
That works fine and returns exactly what I want when I give it a string like that for it's "needle".
However, I want to use a previously declared variable in place of it. Like thus:
$thisCat = $page->title();
$thisCatsPosts = $allPosts->findby('category', $thisCat);
However that does not work. I have also tried putting the variable in quotes.
Some specific notes are that I am using the Kirby CMS so the functions I'm using are from it's docs. I'm a complete PHP novice. From my understanding though, this is a PHP question and not a Kirby related one.
Many thanks for any help.
EDIT: I have checked that $thisCat prints "category-one". I have also checked that the function works when "category-one" is inputted as a string literal.
$thisCat? If you're after a category, are you sure you should be using a function that looks like it returns a page title?$page->title(), according to the doc, already returns a string. There should be no reason for your code to fail unlessfindbyis failing.var_dump($thisCat);and edit the output into your question?$page->title()isn't just returning a string.string(12) "category-one", that function doesn't return what you're expecting)