46cl / wp-boilerplate

[unstable] A Wordpress boilerplate created by 46cl
MIT License
3 stars 1 forks source link

Add a getLinkForPageTemplate Utils function #47

Open jvelo opened 9 years ago

jvelo commented 9 years ago

Proposal :

    /**
     * Get the permalink for first found page associated with a given php template
     *
     * @param $name the name of the template page file
     * @return null if not found, the permalink for the first found page otherwise
     */
    static public function getLinkForPageTemplate($name)
    {
        $page = current(get_posts([
            'post_type' => 'page',
            'meta_key' => '_wp_page_template',
            'meta_value' => $name
        ]));

        return $page ? get_permalink($page->ID) : null;
    }