Support » Fixing WordPress » Excluding pages if there is a particular custom field

  • Resolved nathan12343


    I’ve got a site where different content will be shown if you are looking at it through a desktop or a phone/PDA etc. There are different template files for each.

    I have been trying to exclude certain pages from the mobile version if it has a custom field (e.g. key=for mobile value=no). I wanted to do this in the loop through wp_query() because there is a menu generation in the page that needs to exlude these pages too.

    I can see how to do this inclusively, but I’ve hit a bit of a wall and could do with a helping hand! (I could easily be pursuaded to do the same through a tag (e.g. notMobile) if it is easier.)


Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve been trying out other stuff, and it’s just not working because of a conflict with another function. But it seems to me that all I really need to do is hide it from the menu.

    So, is there a way that I can exlude a page from wp_list_pages because of a tag or a custom field?

    Why doesn’t this work???? I’ve got pages with a custom field of “notmobile” and a value of “notmobile”. These are the only ones that use this field. And this is the only time this value will appear.

    This is the code I’m using:

    $menulist = get_children('meta_compare=!=&meta_value=notmobile&post_type=page&orderby=menu_order&order=ASC&post_parent='.$post->ID);
           if(is_array($menulist) && count($menulist) > 0) :?>
    	   <ul id="relative"><?php foreach ($menulist as $post) : ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
    <?php else : ?>
    <!-- no children -->
    <?php endif; ?>

    If I remove meta_compare=!= then only the two menu items that have a value of “notmobile” appear. Why can’t I get it to exclude them?

    Any help would be really, really appreciated!

    MichaelH sorted this out in another thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding pages if there is a particular custom field’ is closed to new replies.