I’m curious as to if it’s possible to add custom post type loop as a controller, which takes an argument to determine which post type the loop is looking for?
This is not working, with the following error message:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function App\Controllers\TemplateAktiviteter::kursLoop(), 0 passed in soberwp/controller/src/Controller.php on line 191 and exactly 1 expected in Controllers/TemplateAktiviteter.php:9
I’m curious as to if it is possible to create such a loop? It would allow me to work much more DRY
Thanks a lot!! This solved my problem. I made a slight change to your code that made it work the way I want it to, I changed the following: public static function kursLoop($postType)
and @foreach(TemplateAktiviteter::kursLoop('kurs') as $kurs_item)
Ok, I’m running into a problem here which I’m not sure how to solve.
Everything works perfectly, except for getting the permalink from the loop this way. I get all the other fields right, such as title and content, however the permalink is the same as the main page the loop is on.