Home › Forums › Backend Issues (wp-admin) › post object field sort order
Hello…
I have two custom post types which I want to relate to each other. So custom post type “artikel” is a child from “ausgabe”.
I created an custom field called ‘heft’ inside “artikel” to contain the parent information and used post object field type from “post type for a relation. That’s working.
Now, I would like to sort the fields within the select field not in alphabethical order but by publishing date descending.
I tried following your example code
function my_post_object_query( $args, $field, $post )
{
// modify the order
$args['orderby'] = 'title desc';
return $args;
}
// filter for a specific field based on it's name
add_filter('acf/fields/post_object/query/name=heft', 'my_post_object_query', 10, 3);
just to see if it is at all working, but it’s not.
Any advice appreciated.
Hi @hagedorn,
Thanks for the post.
To get this done, you will need the following code:
function my_post_object_query( $args, $field, $post )
{
// modify the order
$args['orderby'] = 'date';
$args['order'] = 'DESC';
return $args;
}
// filter for a specific field based on it's name
add_filter('acf/fields/post_object/query/name=heft', 'my_post_object_query', 10, 3);
Hello,
I’d like to to that too but It doesn’t seem to work. Did something change since ?
Thanks
Hi @realision69
Thanks for reaching out to us.
The code should work just fine.
Kindly a more personalized ticket at [email protected]
Hope to hear from you soon.
Hi @realision69
Thanks for reaching out to us.
The code should work just fine.
Kindly a more personalized ticket at [email protected]
Hope to hear from you soon.
The topic ‘post object field sort order’ is closed to new replies.
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.