Rest-Easy icon indicating copy to clipboard operation
Rest-Easy copied to clipboard

A serializer that can process an entire array

Open drewbaker opened this issue 7 years ago • 0 comments
trafficstars

I find myself doing this pattern a lot when writing a filter:

    $args = array(
        ...
    );
    $attachments = get_posts($args);

    foreach($attachments as $attachment) {
        $post_data['something'][] = apply_filters('rez_serialize_attachment', $attachment);                    
    }

Generally it's for pages/posts or attachments. Would be handy to have a serializer that worked like this:

    $args = array(
        ...
    );
    $attachments = get_posts($args);
    $post_data['something'] = apply_filters('rez_serialize_array', $attachments);                    

I imagine it would then look at the contents of $attachments can correctly serialize a post or an attachment.

drewbaker avatar Mar 20 '18 00:03 drewbaker