Ready to launch your next project?

Contact Us

Notes

Using wp list pluck to extract data from a WP Query Object

Often times, you’ll need to run a WP_Query, but don’t actually need the whole object it returns. Perhaps just the post id’s are all you want.

Previously, I’d take the object, then use a foreach to loop through it, building the array of id’s that I need.

But I’ve just discovered wp_list_pluck which makes this way simpler:

….and that’s it. $post_ids will now be an array of ids.

Sweet.