Support

Account

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' );