sage-directives
sage-directives copied to clipboard
@field inside @posts not working
Awesome plugin! But i have one issue. I can't fetch my ACF field with @field When using the get_field() function it's working as espected. Check code below. Am i missing something?
@php $query = new WP_Query([ 'post_type' => 'product' ]); @endphp
@posts($query)
Working: {{ get_field('config_button', get_post()) }}
Not working: @field('config_button', get_post())
Not working: @field('config_button')
@endposts
Is @field returning in plain text or nothing at all?
Not working: {{ get_field('config_button') }}
Working: {{ get_field('config_button', get_post()) }}
Not working: @field('config_button', get_post())
Not working: @field('config_button')
What is being rendered in the compiled Blade? You can find it in storage/framework/views on Sage 10 or the uploads folder (if I recall) on Sage 9.
https://github.com/Log1x/sage-directives/blob/master/src/Directives/ACF.php#L40-L62
The code is simple for the most part so it's hard to tell what could be messing up when Blade compiles.
I'm using Sage 9.
Compiled Blade:
So 1 is working 2,3 and 4 not.
<?php
$query = new WP_Query([
'post_type' => 'product'
]);
?>
<?php $posts = collect(); ?><?php if (is_a($query, 'WP_Post') || is_numeric($query)) : ?><?php $posts->put('p', is_a($query, 'WP_Post') ? ($query)->ID : $query); ?><?php endif; ?><?php if (is_array($query)) : ?><?php $posts
->put('ignore_sticky_posts', true)
->put('posts_per_page', -1)
->put('post__in', collect($query)
->map(function ($post) {
return is_a($post, 'WP_Post') ? $post->ID : $post;
})->all())
->put('orderby', 'post__in');
?><?php endif; ?><?php $query = $posts->isNotEmpty() ? new WP_Query($posts->all()) : $query; ?><?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<article class="cell large-11 item">
1. <?php echo e(get_field('config_button', get_post())); ?>
2. <?php echo e(get_field('config_button')); ?>
3. <?= get_field('config_button')[get_post()]; ?>
4. <?= get_field('config_button'); ?>
</article>
<?php endwhile; wp_reset_postdata(); endif; ?>
For me too @field don't working, get_field working. But title, content and etc are working. And also yarn docs:build ( docs:dev ) gives me 'Command not found'
Hi all, this still seems to be an issue.
I see in my rendered code it's because it does the following:
<?= get_field('introduction')[$post->ID]; ?>
When it should be:
<?php echo e(get_field("role", $post->ID)); ?>
Is there a fix for this, or is using {{}} the recommended fix?
Thanks