How to use get_posts() function in functions.php

There should be a global declaration of $post at the beginning of the function. Just like this:

function get_my_posts(){
    global $post;
    // rest of the code.
}

Original answer from stackoverflow: xphan

techhipbettruvabetnorabahisbahis forumutaraftarium24edusedusedueduedueduseduedusedusedus