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
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