Hello!
Feels like I might be doing something wrong here, so please advice me if there’s some better way to do what I’m trying to do.
Thing is I’m drying to break up functionality to smaller functions so readability and understanding for what does what will be clearer.
Basically I want to return posts based on date or custom order, depending on some options I set. So I have a switch that checks what option is chosen and then should run different function loops.
However I’m getting Call to undefined function
when trying to call another function from within my controller .
Error message reads Fatal error: Uncaught Error: Call to undefined function App\posts_by_date() in /srv/www/mysite.tld/current/web/app/themes/mytheme/app/controllers/taxonomy-department.php on line *37*
Here’s my code:
<?php
namespace App;
use Sober\Controller\Controller;
class TaxonomyDepartment extends Controller
{
/**
* Return layout name for taxonomy page
*
* @return array
*/
public function department_layout() {
$queried_object = get_queried_object();
$department_slug = $queried_object->slug;
$layout = get_field('layout_' . $department_slug, 'option');
return $layout;
}
/**
* Return posts for taxonomy page
*
* @return array
*/
public function department_posts() {
$queried_object = get_queried_object();
$department_slug = $queried_object->slug;
$order = get_field('order_' . $department_slug, 'option');
switch ($order) {
case 'date':
$posts = posts_by_date();
break;
case 'manual':
$posts = posts_by_custom_order();
break;
default:
$order_is = 'an error has occurred';
}
$posts = posts_by_date();
return $posts;
}
/**
* Load posts by publish date
*
* @return array
*/
public function posts_by_date() {
$posts = 'hello';
return $posts;
}
/**
* Load posts by custom order
*
* @return array
*/
public function posts_by_custom_order() {
$posts = 'goodbye';
return $posts;
}
}