0

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?

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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