Support

Account

Home Forums General Issues Ordering by custom field of relationship field object Reply To: Ordering by custom field of relationship field object

  • So how would I use /query as you mention? In other words do I just change the top part of the code and that is it?

    Like this to add the sorting ASC?

    add_filter('acf/fields/relationship/query/name=jam_related_home_listing', 'my_acf_fields_relationship_query', 10, 5);
    function my_acf_fields_relationship_query( $text, $post, $field, $post_id ) {
    
      $community = get_field ('community', $post->ID);
      $sqft = get_field('sq_ft', $post->ID);
      $mls = get_field('mls', $post->ID);
      $price = get_field('price',$post->ID);
      $lot = get_field('lot', $post->ID);
    	
        if ($post->post_type == 'home_listings') {
    return "wp_posts.menu_order ASC";
    	} 	
            $text .= ' •  ' . $community->post_title .  ' •  Lot:  ' . $lot . '  •  SqFt:  ' . $sqft . ' •  MLS: ' . $mls . ' •  Price:  ' . $price . '';
        }
        return $text;
    }