Support

Account

Home Forums Backend Issues (wp-admin) post object field sort order

Solving

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.

  • Any help would be 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 support@advancedcustomfields.com

    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 support@advancedcustomfields.com

    Hope to hear from you soon.

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

You must be logged in to reply to this topic.