Site icon Hip-Hop Website Design and Development

Show Mother or father-Youngster Posts in particular order by evaluating IDs in array

I’ve an array of IDs saved for customized submit sort "service".
A few of these are dad or mum IDs and a few of these are youngster IDs.

So "service" submit sort right here is hierarchical.

Now from this array of IDS, I need to checklist pages within the format in order that

  1. they’re sorted by submit title, ascending order
  2. they’re listed in dad or mum > youngster sample like this

Service 1
A Youngster
B Youngster
Service 2
X Youngster
Y Youngster
Service 3

  1. additionally because the array accommodates any IDs. if there may be Youngster id within the array however dad or mum ID shouldn’t be then present the dad or mum id mechanically.

To date beneath is the code I’ve carried out:

$args = array(
    'post_type' => array( 'service' ),
    'posts_per_page' => '-1',
    'orderby' => 'title',
    'order' => 'ASC',
    'post__in' => $service_ids_array,
);

$all_services = new WP_Query( $args );

However, this simply will get all of the providers from the array of IDs ordered by title.

Here’s a logic I’m making an attempt to implement but when there’s a higher answer, I’m completely satisfied to make use of that.

So my logic was, to get all of the posts from array which can be on root degree. so dad or mum id = 0.
After that I run a loop of those ids and within the loop I examine if their youngster ids exists within the $service_ids_array or not. And present if it exists.

However what if there are solely youngster ids within the array? in that case this logic won’t succeed.