Code fails in plugin file but works in functions.php
You need to use a hook and a function in your plugin file. For example: function sher_posts() { $pages = get_posts($args); foreach($pages as $page) { $out = get_permalink($page->ID); } } add_action(‘wp’, ‘sher_posts’); Of course this example doesn’t know what $args are or what to do with $out.