get_posts Not Working in Widget WordPress

Today I ran into a frustrating issue where a simple “get_posts()” query was not working in a custom widget.  The query worked fine when embedded into the page template.

The solution was actually quite simple – calling global $post; before my query in the widget did the job!

Movin’ on up!

Thanks to Aaron  and Matt for helping find a solution!

Posted in

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to twitter.com/tobycryns and twitter.com/themightymo

Follow Toby's contributions on Github and WP.org.