Support

Account

Home Forums Backend Issues (wp-admin) Hierarchical Custom Posts using Relationship custom field Reply To: Hierarchical Custom Posts using Relationship custom field

  • Hey

    Thanks for the reply.

    That helps a little. I now have this filter in place, which as you say, orders the posts by menu_order.

    // filter for every field
    add_filter('acf/fields/relationship/query', 'my_relationship_query', 10, 3);
    function acf_relationship_query( $args, $field, $post )
    {
        $args['orderby'] = 'menu_order'; 
        return $args;
    }

    But, this takes the menu_order as is. By this I mean, you would have a root level post with a menu_order of 1. But you also have a child of a root level post also with a menu_order of 1. This means that the posts aren’t in a hierarchical order still.

    Using my example in the first post, you would now have:

    1/ Electrical Items
    1.1/Drills
    3.1/ Bricks
    1.2/Mowers
    2/ Timber
    3.2/ Plumbimg
    3/ Building Materials

    Really what I need to be able to do is create a recursive function that orders the posts under a specific post, and return them in an ordered array?