0

I have added a custom field (using Advanced Custom Fields plugin) to a page allowing you to show/hide it with a simple checkbox, i want to filter out these pages if a user is not logged in so i am doing the following:

if( !is_user_logged_in() ):
  $args = array(
    'title_li' => '',
    'meta_key' => 'private',
    'meta_value' => 0
  );
else:
  $args = array(
    'title_li' => '',
    'meta_key' => 'private',
    'meta_value' => 1
  );
endif;

wp_list_pages($args);

So i want it to show all pages where the custom variable is 0 is not logged in and 1 if they are.

Logged in, works fine. Only shows the private pages in the menu.

Not logged in, shows all pages no matter what the value is.

I have tried adding meta_compare and also changing meta_value to meta_value_num but neither have worked.

3
  • 2
    I think the problem may be that 0 does not exist, or it's considered false, or something along the lines. Although not recommended when dealing with true/false variables, what if you try yes/no to the meta value? – brasofilo Apr 12 '13 at 17:01
  • Thanks, that seems to have fixed it. It didn't like them being integers for some reason but as soon as i added radios with strings for 'yes' or 'no' these work well! – benpalmer Apr 14 '13 at 9:06
  • Hi @brasofilo, this question is coming up in our unanswered list. Would you like to add your comment as an answer so it can be upvoted/accepted? Thanks! – Tim Malone Aug 3 '16 at 1:12

Your Answer

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

Browse other questions tagged or ask your own question.