WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding pages if there is a particular custom field (4 posts)

  1. nathan12343
    Member
    Posted 4 years ago #

    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.)

    Thanks

  2. nathan12343
    Member
    Posted 4 years ago #

    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?

  3. nathan12343
    Member
    Posted 4 years ago #

    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:

    <?php
    $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; ?>
    </ul>
    <?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!

  4. nathan12343
    Member
    Posted 4 years ago #

    MichaelH sorted this out in another thread.

    http://wordpress.org/support/topic/320032?replies=16

Topic Closed

This topic has been closed to new replies.

About this Topic