Displaying Custom Post Type with Composer

Hi, that may be a noob question but I didn’t find answers in the forum so I need to ask. Sorry about that, really.

So I created a Composer called ‘Company’ with this code:

'<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;

class Company extends Composer
{
/**
* List of views served by this composer.
*
* @var string
*/
protected static $views = [
‘partials.content’,
];

/**
 * Data to be passed to view before rendering, but after merging.
 *
 * @return array
 */
public function override()
{
    return [
        'title' => $this->title(),
    ];
}

/**
 * Retrieve the post title.
 *
 * @return string
 */
public function title()
{       
    return get_the_title();
}

}’

And a content.blade with:

'<article @php(post_class())>



{{!! $title !!}}

</header>

<div class="entry-summary">
    @php(the_excerpt())
</div>
'

And in my index file:

@while(have_posts()) @php(the_post())
@includeFirst([‘partials.content-’ . get_post_type(‘empresa’), ‘partials.content’])
@endwhile

So I didn’t add any custom meta yet, but even with ‘empresa’ in the get_post_type I still get the normal posts (Hello World). Can somebody tell me what I’ve missed?

I did it, sorry to bother

Solution:

<?php namespace App\View\Composers; use Roots\Acorn\View\Composer; class Company extends Composer { /** * List of views served by this composer. * * @var string[] */ protected static $views = [ 'partials.content', ]; /** * Data to be passed to view before rendering, but after merging. * * @return array */ public function override() { return [ 'title' => $this->title(), 'cnpj_data' => $this->cnpj_data(), 'cnpj' => $this->cnpj(), ]; } /** * Retrieve the company title. * * @return string */ public function title() { return get_the_title(); } /** * Retrieve the company CNPJ group meta. * * @return string */ public function cnpj_data() { return get_field('dados_de_cnpj'); } /** * Retrieve the company CNPJ code. * * @return string */ public function cnpj() { $cnpj_data = get_field('dados_de_cnpj'); return esc_attr($cnpj_data['cnpj']); } } And @php $args = [ 'post_type' => 'empresa', 'status' => 'publish', 'order' => 'DESC', 'posts_per_page' => 16, ]; $query = new WP_Query($args); @endphp @if ($query->have_posts()) @while ($query->have_posts()) @php $query->the_post(); @endphp @includeFirst(['partials.content-' . get_post_type(), 'partials.content']) @endwhile @endif

Please format your code when posting it