I have this query –
<?php if( is_page_template('taxonomy-listing_area-channel.php') ) { ?>
<?php
$posts = get_posts(array(
'post_type' => 'adverts',
'numberposts' => 1,
'order' => 'random',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'associate_adverts',
'value' => '204',
'compare' => 'LIKE',
)
),
));
?>
<?php //if it's returning the object
foreach($posts as $advert){
$img = get_field("top_advert", $advert->ID);?>
<img src="<?php echo $img["url"]; ?>"/>
<?php }?>
But for somr reaosn the posts are just showing as the last one entered and now randomly, I’ve never had this problem before but I have no idea where I’m going wrong, and help would be much appreciated!
Change here, You have syntax error, use single quotes inside double quotes,
You need to change this
To
Now you code will look like
Also you forgot to close you
if
statement.Thanks for all the help,
It turns out it was a box that needed to be click on WPEngine to allow the random function in a query!