WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do something like this: Hide a page in the admin end without a plugin?

However, I don't want to hardcode the page-ids. I want to get the page id's based on template-name.

$pages = get_posts(array(
        'post_type' => 'page',
    'meta_key' => '_wp_page_template',
    'meta_value' => 'product.php'

^^This probably does the job, but it gets entire pages, and I start worrying about efficiency, especially when I only need id's and there could be thousands of pages being returned by this command.

I know SQL pretty well, so if I should just write my own query, then let me know.

Or maybe I don't need to worry about this at all?

share|improve this question
up vote 1 down vote accepted

Use the parameter 'fields':

$pages = get_posts(
        'post_type'  => 'page',
        'meta_key'   => '_wp_page_template',
        'meta_value' => 'product.php',
        'fields'     => 'ids'

Not tested, but it should fetch just the IDs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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