I'm using get_pages in a Wordpress theme to create the nav.

I have some pages I don't want to show in the nav.

On all pages I have a 'dont_show_in_nav' true/false custom field.

I can use meta_key to add pages that have 'dont_show_in_nav' selected but I'd like to not show the pages that have 'dont_show_in_nav' selected.

I could create a 'show_in_nav' custom field and select all the pages to show but I have to many pages to do that.

I've tried 'meta_value' => false

    $pages_args = array(
      'sort_column' => 'menu_order',
      'parent' => 0,
      'post_type' => 'page',
      'post_status' => 'publish',
      'meta_key'  => 'dont_show_in_nav',
      'meta_value' => true
  • 1
    Are you certain your custom field contains true/false booleans and not just the text true/false ? If not, try setting your meta_value to: 'true' - With the '' symbols (ticks). – Jeppe Aug 19 '15 at 20:25

For the reasons I probably don't want to hear about, curiously get_pages() does not actually uses WP_Query internally. Like every other way to retrieve posts does.

From a quick look a source it always treats meta_value as string, which I would guess is the reason for you not getting expected behavior.

I would suggest to try use get_posts() instead for more consistency with usual mechanics.

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.