Hello I was trying to filter the pages using a custom filter in admin post listing of wordpress, but after selecting in the dropdown it returns nothing like its just showing all the posts and the dropdown text returns to its default text "Show all Templates". Please help, I just cant figure it out why its not really working.

after I click the Filter button, the url is:


heres the screenshot:


heres my code:

function pagetemplates_request_admin($request) {
if( isset($_GET['_wp_page_template']) && !empty($_GET['_wp_page_template']) ) {
    $request['meta_key'] = '_wp_page_template';
    $request['meta_value'] = $_GET['template'];
return $request;}


function pagetemplates_restrict_manage_posts() {
global $wpdb;
$optemplate ='';
$templates = $wpdb->get_col("
    SELECT DISTINCT meta_value
    FROM ". $wpdb->postmeta ."
    WHERE meta_key = '_wp_page_template'
    ORDER BY meta_value
 <select name="template" id="template">
     <option value="">Show all Templates</option>
     <?php foreach ($templates as $template) { ?>
     <option value="<?php echo esc_attr( $template ); ?>" <?php if(isset($_GET['_wp_page_template']) && !empty($_GET['_wp_page_template']) ) selected($_GET['_wp_page_template'], $template); ?>>

            $optemplate = esc_attr($template); 
            switch ($optemplate)
                    case 'template1.php';
                        echo 'Blog Page Template 1';
                    case 'template2.php';
                        echo 'Blog Page Template 2';
                        echo 'Default Template';
     <?php } ?>



if( is_admin() && isset($_GET['post_type']) && $_GET['post_type'] == 'page' ) {
add_filter('request', 'pagetemplates_request_admin');
add_filter('restrict_manage_posts', 'pagetemplates_restrict_manage_posts');}

1 Answer 1


The initial thing that jumps out is that you're using:


in the URL, but in the code you are using

if( isset($_GET['_wp_page_template']) && !empty($_GET['_wp_page_template']) ) {

you should be checking:

if( isset($_GET['template']) && !empty($_GET['template']) ) {

Also, don't forget to sanitize the $_GET as that's user input and cannot be trusted.

Hope that helps.

  • Hello Steven, I tested it again and removed other codes I made after I posted my code here.,IT WORKS NOW !!! And I really thank God for the help you gave...
    – Kiko Lolo
    Commented Apr 26, 2014 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.