Home › Forums › Front-end Issues › get_field() returns null › Reply To: get_field() returns null
also for some really odd reason some times it displays on few products, some times displays on all of them but for the past few hours it is not displaying on any of them
add_shortcode( 'ek_prod', 'ran_fun' );
function ran_fun($atts) {
$atts = shortcode_atts($default, $atts);
ob_start();
?>
<div>
<ul class="ek-grid">
<?php
$args = array(
'limit' => 5,
'order' => 'DESC',
'post_type' => 'products',
'status' => 'publish',
'orderby' => 'rand',
);
$products = wc_get_products( $args );
if ($products) {
foreach ($products as $product ) {
$permalink = get_permalink(get_the_id($product));
?>
<li class="ek-li">
<a href="<?php echo $product->get_permalink() ?>">
<img src="<?php echo wp_get_attachment_url( $product->get_image_id() )?>" alt="">
<h2><?php echo $product->get_title()?></h2>
<h3><?php echo get_field("platform", $product->get_id())?></h3>
<h4><?php echo get_field("region", $product->get_id())?></h4>
<bdi><span>$</span><?php echo $product->get_price()?></bdi>
</a>
</li>
<?php
}
}
?>
</ul>
</div>
<?php
return ob_get_clean();
}
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.