I’m trying to get a page which uses a specific template. I have the page_id.
Here is my code :
$pids = $wpdb->get_col( $wpdb->prepare(
"SELECT ID FROM {$wpdb->posts}
WHERE post_author = %d AND post_status = 'publish'
AND post_type='page'", $user->ID
) );
foreach($pids as $post_id)
{
wp_set_post_terms( $post_id, $tag, $taxonomy );
// I need permalink only if that page use a specific template (say blog.php)
$permalink_n = get_permalink($post_id);
set_cimyFieldValue( $user_id, 'HOMEPAGE', $permalink_n );
}
Page template is set in a post meta field keyed
'_wp_page_template'
so, instead of using raw$wpdb
query, you can run aWP_Query
using'author'
argument andmeta_query
to retrieve pages from a specific author that also have a specific templates:If you want retrieve all pages from an author, but do something for all pages and something else only for some other pages you can