add_action(\'admin_menu\',\'add_home_page_menu\');
add_action(\'load-edit.php\', \'filter_home_pages_mysql_action\');
function add_home_page_menu(){
add_pages_page(\'Home Pages Menu\', \'Home Pages\', \'manage_options\', \'edit.php?post_type=page&page_template=home_pages\');
add_pages_page(\'Landing Pages Menu\', \'Landing Pages\', \'manage_options\', \'edit.php?post_type=page&page_template=landing_pages\');
}
function filter_home_pages_mysql_action() {
if ($_GET[\'post_type\'] !== \'page\') return;
switch($_GET[\'page_template\']){
case \'home_pages\':
add_filter(\'posts_where\', \'home_pages_where_filter\') );
add_filter(\'posts_join\', \'join_filter\') );
break;
case \'landing_pages\':
add_filter(\'posts_where\', \'landing_pages_where_filter\') );
add_filter(\'posts_join\', \'join_filter\') );
break;
default:
break;
}
}
function home_pages_where_filter($sql) {
global $wpdb;
$sql = " AND $wpdb->postmeta.meta_key = \'_wp_page_template\' AND $wpdb->postmeta.meta_value LIKE \'template-homepage-grid-%.php\'" . $sql;
return $sql;
}
function landing_pages_where_filter($sql) {
global $wpdb;
$sql = " AND $wpdb->postmeta.meta_key = \'_wp_page_template\' AND $wpdb->postmeta.meta_value LIKE \'template-landing.php\'" . $sql;
return $sql;
}
function join_filter($sql) {
global $wpdb;
$sql = " JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id " . $sql;
return $sql;
}