Home › Forums › General Issues › Related posts by ACF field value
I have an ACF field called sale_or_charter with three radio options – for sale, charter or new build.
Each custom post type will have one of these values – I would like to then display related posts that have the same value for the sale_or_charter field as the current page.
I can’t work out what i am doing wrong?
Any help appreciated
<?php
$type = get_field( "sale_or_charter", get_the_ID() );
$args = array(
'post_type' => 'yachts',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'sale_or_charter',
'value' => $type
)
),
);
$my_posts = new WP_Query($args);
if ( $my_posts->have_posts() ) {
while ( $my_posts->have_posts() ) : $my_posts->the_post();
After all that – I realised I had the field value set to label not value!
You must be logged in to reply to this topic.
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.