Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mohammadYousefiDev/7996fd2ab817524c71e66c361419a6be to your computer and use it in GitHub Desktop.
Save mohammadYousefiDev/7996fd2ab817524c71e66c361419a6be to your computer and use it in GitHub Desktop.
sort netsted record in wp
//referral post type
//iranam plugin
function sort_referral($mains, $user_id)
{
$result = [];
foreach( $mains as $key=>$main )
{
$data = $main;
if( (int)$main->post_author == $user_id )
{
$email = $main->post_content;
$user = get_user_by( 'email', $email );
$id = $user->ID;
$mains[$key]->child = $this->sort_referral($mains, $id);
$result[] = $main;
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment