i want to get template page URL in WordPress and i create a function
function getTplPageURL($TEMPLATE_NAME){
$url;
//Code which i need
$pages = query_posts(array(
'post_type' =>'page',
'meta_key' =>'_wp_page_template',
'meta_value'=> $TEMPLATE_NAME
));
// cycle through $pages here and either grab the URL
// from the results or do get_page_link($id) with
// the id of the page you want
$url = null;
if(isset($pages[0])) {
$url = get_page_link($pages[0]['ID']);
}
return $url;
}
but when i call this function this error has occurred
” Fatal error: Cannot use object of type WP_Post as array”
please help me
Use the following standard WP function:
Why complicate things?
Output: http://your-wordpress-url.com/wp-content/themes/yourtheme
Reference
It seems that
$pages[0]
is an object(WP_Post
).Try change
$pages[0]['ID']
to$pages[0]->ID
.