5238 | | ?> |
5239 | | No newline at end of file |
| 5238 | /** |
| 5239 | * Return array of posts for post_type='page' for those pages with the given page template. |
| 5240 | * |
| 5241 | * @param string $template Filename of the assigned template for a page. |
| 5242 | * |
| 5243 | * @return array The posts that have a template matching the one passed. |
| 5244 | */ |
| 5245 | function get_pages_by_template( $template ) { |
| 5246 | global $wpdb; |
| 5247 | $sql = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_wp_page_template' AND meta_value LIKE '%s'"; |
| 5248 | $sql = $wpdb->prepare( $sql, $template . '%' ); // '%' to allow partial matches |
| 5249 | $pages = $wpdb->get_col($sql); |
| 5250 | foreach( $pages as $index => $page_id ) |
| 5251 | $pages[$page_id] = get_post( $page_id ); |
| 5252 | return apply_filters( 'get_pages_by_template', $pages, $template ); |
| 5253 | } |
| 5254 | |
| 5255 | ?> |