Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 down vote accepted

Use the parameter 'fields':

$pages = get_posts(
    array(
        '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
add comment

Your Answer

 
discard

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.