页面模板在键入的post meta字段中设置\'_wp_page_template\'
所以,不要使用raw$wpdb
查询,您可以运行WP_Query
使用\'author\'
参数和meta_query
要从具有特定模板的特定作者检索页面,请执行以下操作:
$q = new WP_Query( array(
\'author\' => $user->ID,
\'post_type\' => \'page\',
\'meta_query\' => array( array(\'key\' => \'_wp_page_template\', \'value\' => \'blog.php\') )
) );
if ( $q->found_posts > 0 ) {
foreach ( $q->posts as $post ) {
// all pages returned have the template `\'blog.php\'`
wp_set_post_terms( $post->ID, $tag, $taxonomy );
$permalink_n = get_permalink($post);
set_cimyFieldValue( $user->ID, \'HOMEPAGE\', $permalink_n );
}
}
如果您想从作者处检索所有页面,但对所有页面执行某些操作,而对其他页面执行某些操作,则可以
$q = new WP_Query( array(
\'author\' => $user->ID,
\'post_type\' => \'page\'
) );
if ( $q->found_posts > 0 ) {
foreach ( $q->posts as $post ) {
wp_set_post_terms( $post->ID, $tag, $taxonomy );
$template = get_post_meta( $post->ID, \'_wp_page_template\', true );
if ( $template === \'blog.php\' ) {
$permalink_n = get_permalink($post);
set_cimyFieldValue( $user->ID, \'HOMEPAGE\', $permalink_n );
}
}
}