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.

Direct URL to a template via plugin

This really isn’t the best use for wordpress. You are better off creating a custom post type called “profile” (see https://codex.wordpress.org/Function_Reference/register_post_type or use a plugin like PODS) and then the URL rewrites are all done for you. You can enable / disable the archive page so that domain.com/profile lists all profiles or not at all. … Read more