Hi
I have created a custom post type using ACF and I call it from my composer and it works great - but I need to get it to sort by my terms dynamically so that if I add another category it still work so I don’t have to manually add the category to the controller.
In Sage 9 it could be done with a static function in the controller - but I cant get it to work with Sage10.
My Composer looks like this
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
use WP_Query;
class Bolig extends Composer
{
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'partials.content-bolig',
];
/**
* Data to be passed to view before rendering.
*
* @return array
*/
public function override()
{
return [
'boliger' => $this->boliger(),
];
}
public static function boliger()
{
$args = [
'post_type' => 'bolig',
'posts_per_page' => -1,
'order' => 'DESC',
'tax_query' => [
[
'taxonomy' => 'boligtype',
'field' => 'slug',
'terms' => $terms,
],
],
];
$query = new WP_Query($args);
return $query->posts;
}
}
And my view looks like this
<div class="section boligOuter">
@foreach ($boliger as $bolig)
@php
$term = get_the_terms($bolig->ID, 'omrade');
@endphp
<div class="bolig">
<div class="bolig__image">
<img src="{{ get_the_post_thumbnail_url($bolig->ID) }}" alt="{{ $bolig->post_title }}">
</div>
<div class="bolig__content">
<h2>{{ $bolig->post_title }}</h2>
<p>{{ $term[0]->name }}</p>
<p>{{ $bolig->post_content }}</p>
<a href="{{ get_permalink($bolig->ID) }}" class="button">Se bolig</a>
</div>
@endforeach
</div>
I was hoping to send the $term variable over to my composer to use this inside the query - but it is not working.
Hope someone can help me figure this out - thanks in advance