0
votes

I see that this issue has been flagged on Timber's repo previously, however in 2021 this solution doesn't seem to work for me. I am trying to render the featured image for a custom post type which itself is being rendered via an ACF repeater field.

In the Twig template, I am able to render other components of the custom post type (i.e. ID, post_title) without issue:

{% for hosting in hosting_providers %}
    {% set hosting_image = TimberImage(hosting.thumbnail) %}
        <tr class="domain-connector__tool-form-hosting">
            <td class="border-none">
                <label>
                    <table>
                        <tr>
                            <td class="border-none"><input type="radio" name="hosting-provider" value={{ hosting.ID }} class="hosting-provider__input"/></td>
                            <td class="border-none"><img src="{{ hosting_image.src|resize('full') }}"></td>
                            <td class="border-none"><p>{{ hosting.post_title }}</p></td>
                        </tr>
                    </table>
                </label>
            </td>
        </tr>
{% endfor %}

Interestingly, when I try to debug this with a var_dump there doesn't even seem to be a thumbnail for the custom post type that I can access:

object(WP_Post)[3942]
  public 'ID' => int 2372
  public 'post_author' => string '1' (length=1)
  public 'post_date' => string '2021-01-28 23:01:04' (length=19)
  public 'post_date_gmt' => string '2021-01-28 23:01:04' (length=19)
  public 'post_content' => string '' (length=0)
  public 'post_title' => string 'Namecheap' (length=9)
  public 'post_excerpt' => string '' (length=0)
  public 'post_status' => string 'publish' (length=7)
  public 'comment_status' => string 'open' (length=4)
  public 'ping_status' => string 'open' (length=4)
  public 'post_password' => string '' (length=0)
  public 'post_name' => string 'namecheap' (length=9)
  public 'to_ping' => string '' (length=0)
  public 'pinged' => string '' (length=0)
  public 'post_modified' => string '2021-01-30 10:49:36' (length=19)
  public 'post_modified_gmt' => string '2021-01-30 10:49:36' (length=19)
  public 'post_content_filtered' => string '' (length=0)
  public 'post_parent' => int 0
  public 'guid' => string 'http://websitetooltesternew.local/blog/wtt_objects/namecheap/' (length=61)
  public 'menu_order' => int 0
  public 'post_type' => string 'wtt_objects' (length=11)
  public 'post_mime_type' => string '' (length=0)
  public 'comment_count' => string '0' (length=1)
  public 'filter' => string 'raw' (length=3)

Which would explain why nothing gets rendered. But my question is, where did the featured image go? I am rewriting the current theme in the Timber environment, and things seem to render fine in the original theme (PHP / HTML spaghetti code).

1

1 Answers

0
votes

Is the post data in a Timber\Post?

This is the object you use to access or extend WordPress posts. Think of it as Timber's (more accessible) version of WP_Post.

For example:

$context = Timber::context();

$args = array(
    'post_type' => 'custom_post_type',
);

$context['custom_post_type'] = Timerb:get_posts($args);
Timber::render('view.twig', $context);

You can check this using {{ dump( post ) }} (with debug enabled) and it'll say Timber\Post in the output.