Home › Forums › Front-end Issues › get_field is null / trying to display a field on a post skin
Hi, im trying to displaying a field on a post widget on an elemenetor post skin.
On homepage it works, but when the widget is saved as a template on EA advanced tabs, it cant seem to pull the field value at all. Please view clublandkl.com and see the What’s hot section (which displays correctly) but the “upcoming parties” section doesnt have the date on the badge of the card.
Here is what I found out in my code:
public function render_badge() {
$value = get_field( 'event_date_field', false );
$event_date_field = $this->get_instance_value( 'event_date_field' );
if ( ! empty( $event_date_field ) && function_exists( 'get_field' ) ) {
$event_date = get_field( $event_date_field );
if ( ! empty( $event_date ) ) {
?>
<div class="elementor-post__badge" style="z-index: 9999;">
<?php echo esc_html( $event_date ); ?>
</div>
<?php
// Output the event_date value to the browser console
echo '<script>console.log("' . $value . '");</script>';
}
}
}
$value is null, but when going thru the condition $event_date_field shows the value on the badge.
My widget structure is Widget A (whats hot section) which the widget is directly on the homepage itself, Section Template with Widget B inside it (weekly parties) where the widget is in a template that is in another widget called Advance tabs by EA.
Im not good with PHP but i assume that the section template is messing up the $this instance.
But eitherways the $value is null.
I’ve tried every combination to directly pull the field value, but it only works thru the instance.
I think one way is to directly pull the field value correctly and populate $value without relying on the instance since the section template is probably “blocking” that or something.
do let me know if there are any solutions to this! I think its a pretty simple fix, but im not good at PHP at all.
Thank you in advance
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.