WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a custom theme for wordpress, which will have a settings page. i am adding the option to exclude pages from the navigation, which will simply work on the page id separated by a ","

here is the code i have so far:

    <ul class="tabs">
    $exmenuitems = get_option('exmenuitems');
    $recentPosts = new WP_Query();
    $recentPosts->query (array (
    'post__not_in' => array($exmenuitems),
    'post_type' => 'page',
    'showposts' => $menuitems
 while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<?php $slug = basename(get_permalink());?>   
<li><a href="#<?php echo $slug; ?>"><?php the_title();?></a></li>
<?php endwhile; ?>

this works fine excluding just 1 page id. but when i try and exclude more than 1 id it doesn't work, only the first id in the text input will get excluded and the other remain visible.

any help would be greatly appreciated.


share|improve this question

migrated from stackoverflow.com Apr 10 '12 at 3:31

This question came from our site for professional and enthusiast programmers.

Does your $exmenuitems contains an array of page Ids? – The Alpha Apr 9 '12 at 21:44
yes it currently has 3 id's – danyo Apr 9 '12 at 21:48
May be you should use 'post__not_in' => $exmenuitems because it's already an array. – The Alpha Apr 9 '12 at 21:51
showposts should contain an int value and it's deprecated, instead you should use posts_per_page, codex.wordpress.org/Class_Reference/… – The Alpha Apr 9 '12 at 21:53
up vote 2 down vote accepted

You probably want to explode your list of page ID's using the explode function.

Something like;

    $exmenuitems = explode(",",get_option('exmenuitems'));
    $recentPosts = new WP_Query();
    $recentPosts->query (array (
    'post__not_in' => $exmenuitems,
    'post_type' => 'page',
    'showposts' => $menuitems

I'd recommend using the WordPress Menu building functions and admin interface. Its much more intuitive for end users to build their navigation menus via drag n drop that using page ID's.

share|improve this answer
i have tried the explode fnuction and doesn't seem to work. when i echo it out i just get "array" – danyo Apr 9 '12 at 21:53
cheers guys solved! – danyo Apr 9 '12 at 21:54
How did you solve it, would you mind to share ? – The Alpha Apr 9 '12 at 21:55
i did what you said and removed the array from the 'post__not_in' and also used the explode function as Dale stated. – danyo Apr 9 '12 at 21:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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