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;
}
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.