I have a site where I've got a post type called 'small banners' which are basically adverts that i need to call on normal pages (This is fine, I've done this) but I also need to use this functionality on a Taxonomy term.
ACF doesn't have the functionality to select taxonomy terms themselves just to filter the posts within them to select.
How can I do this?
This is my code for calling the adverts on a normal page -
<div id="small-banner-top">
<?php
$smallbanners = get_posts(array(
'post_type' => 'small-banner',
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => 'show_on_post', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<div class="my-slider" style="width: 380px;">
<ul>
<?php if( $smallbanners ): ?>
<?php foreach( $smallbanners as $smallbanner ): ?>
<?php
$photo = get_field('small_banner_image', $smallbanner->ID);
$bannerlink = get_field('url', $smallbanner->ID);
?>
<li>
<a href="<?php echo $bannerlink; ?>">
<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>">
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div>
So far I've just used the taxonomy field option and selected which taxonomy terms I'd like it to show on using this and used this code on a custom page called taxonomy-directory_entry_type.php (the taxonomy terms are called directory entry types).
<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$smallbanners = get_posts(array(
'post_type' => 'small-banner',
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => 'show_on_tax', // name of custom field
'compare' => 'LIKE'
)
)
));
?>
<div class="my-slider" style="width: 380px;">
<ul>
<?php if( $smallbanners ): ?>
<?php foreach( $smallbanners as $smallbanner ): ?>
<?php
$photo = get_field('small_banner_image', $smallbanner->ID);
$bannerlink = get_field('url', $smallbanner->ID);
?>
<li>
<a href="<?php echo $bannerlink; ?>">
<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>">
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
This is bringing in all the adverts but I'm struggling on how to create the logic for it to only bring in the selected adverts. Any help would be much appreciated,
Thanks!