Home Forums General Issues Related posts by ACF field value


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

                                                       $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(
                                                                   '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!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.