Home › Forums › General Issues › Displaying post_object content within shortcode › Reply To: Displaying post_object content within shortcode
Hi John, Thanks for the reply – I had only included the part relevant to the post_object field, full shortcode is below:
function productlist_func( $atts ){
$output = new WP_Query( array(
'post_type' => 'product',
'tag' => $atts['tag'],
'posts_per_page' => 100,
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'meta_key' => 'positioning',
'orderby'=> array(
'meta_value' => 'DESC',
'date' => 'DESC'
)
)
);
if ($output->have_posts()) :
$ret = '<div class="productcont">';
while ($output->have_posts()) : $output->the_post();
$ret .= '
<div class="productitem">
<div class="pilogo">
<div class="sqlogo">';
$brand = get_field('brand');
if( $brand ) :
$ret .= '<img src="' . get_field('square_logo', $brand->ID) . '" />';
endif;
$ret .= '</div>
</div>
<div class="pidetails">
<div class="pititle">
<a href="' . get_permalink() . '">' . get_field('product_title') . '</a>
</div>
<div class="pitext">' . get_field('description') . '</div>
</div>
<div class="eovisit">
<a href="' . get_permalink() . '" class="pbutton">Claim</a>
<div class="piterms">T&Cs apply 18+</div>
</div>
</div>
';
endwhile;
wp_reset_postdata();
$ret .= '</div>';
return $ret;
endif;
}
add_shortcode( 'productlist', 'productlist_func' );
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.