Is there a way to order children of post?

there is a main post:

$parent = wp_insert_post([
‘post_type’ => ‘parent’,
‘post_name’ => ‘test parent’
]);

and the children:

$child1 = wp_insert_post([
‘post_type’ => ‘child’,
‘post_name’ => ‘test child1’
]);
$child2 = wp_insert_post([
‘post_type’ => ‘child’,
‘post_name’ => ‘test child2’
]);
$child3 = wp_insert_post([
‘post_type’ => ‘child’,
‘post_name’ => ‘test child3’
]);

lets match them:

wp_update_post(
array(‘ID’ => $child1, ‘post_parent’ => $parent)
);
wp_update_post(
array(‘ID’ => $child2, ‘post_parent’ => $parent)
);
wp_update_post(
array(‘ID’ => $child3, ‘post_parent’ => $parent)
);

finally to list them:

$children = get_children([‘post_parent’ => $parent]);

this is theoretically seems to be OK, but it only describes the relation itself, not the order. What if I want to order the children? How to do it?

Read more here:: Is there a way to order children of post?

Leave a Reply

Your email address will not be published. Required fields are marked *