For the 2 custom post types Homes and Places, as described here:
https://support.advancedcustomfields.com/forums/topic/filter-relationship-field-of-post-type/
A Home post can select to be linked with a place through the ACFpro Object Field.
Now back to the Homes Admin List, I added a custom column for Places and would like to make this column sortable.
However when I sort, the sorting is based on Place ID. Is it possible to make it sorting Alphabetically based on Place post_title?
add_action( 'pre_get_posts', 'homes_orderby_places' );
function homes_orderby_places( $query ) {
if( ! is_admin() || ! $query->is_main_query() ) {
return;
}
if ( 'place' === $query->get( 'orderby') ) {
$query->set( 'orderby', 'meta_value' );
$query->set( 'meta_key', 'place' );
}
}
No, not directly. The value stored in ‘place’ is the post ID. There is nothing stored for the ‘Homes’ post that has this information.
In order to do this you would need to create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/
In this filter you would need to get the post title, or whatever it is from the other post that you really want to sort by and then save this value for the “Place” post in another meta value https://codex.wordpress.org/Function_Reference/add_post_meta
I cover this idea for repeater fields here https://acfextras.com/dont-query-repeaters/ but the principle would be the same for this, you’re just using different information.