How can I exclude a specific ID from this line of code?

I am using this code to list pages with a specific letter at the beginning of them:

$first_char = 'H';
        echo '<table class="alphabet" style="border:0px;border-color:transparent;">
                    <tbody><tr>
                        <td width="100px;" style="border-color:transparent;"><span class="separator-line"></span></td>
                        <td style="border-color:transparent;padding-left:5px;padding-right:5px;"><span class="letter"><strong>' . $first_char . '</strong></span></td>
                        <td width="100px;" style="border-color:transparent;"><span class="separator-line"></span></td>
                    </tr>
                </tbody></table>';
        $postids=$wpdb->get_col($wpdb->prepare("
        SELECT      ID
        FROM        $wpdb->posts
        WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
        ORDER BY    $wpdb->posts.post_title",$first_char)); 

        if ($postids) {
        $args=array(
          'post__in' => $postids,
          'post_type' => 'page',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1.,
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts()) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php
          endwhile;
        }
        wp_reset_query();  // Restore global post data stomped by the_post().
        }

Basically I need to be able to exclude specific IDs from it. I've tried adding an 'exclude' => '//id' to the $args array, but that did nothing.

Solutions

On a seperate note, 'caller_get_posts' was deprecated in version 3.1 - use 'ignore_sticky_posts' with a boolean argument instead.

'exclude' is not a query argument so WordPress ignores it. Post exclusion via query is done using the key 'post__not_in' with a single post ID or array of IDs instead. However as @vancoder points out, the argument produces computationally expensive queries.

It's also unreasonable to apply both a 'post__in' argument as well as a 'post__not_in' argument as setting one implicitly describes the value of the other. A simpler and more efficient solution is available whenever you might desire to use both: just exclude post IDs from the 'post__in' argument before applying it to the query:

$included_post_ids = $wpdb->get_col( /* ... */ );
$excluded_post_ids = [ /* ids to exclude */ ];

if( !empty( $included_post_ids ) ) {
  $included_post_ids = array_diff( $included_post_ids, $excluded_post_ids );

  $args = [
    'post__in'            => $included_post_ids,
    'post_type'           => 'page',
    'post_status'         => 'publish',
    'posts_per_page'      => -1,
    'ignore_sticky_posts' => true
  ];

  $my_query = new WP_Query( $args );

  // ....
}

Information regarding query arguments can be found in the WP_Query reference on the Codex.

Similar questions

Vertical aligning single line items in a double line navigation menu
I'm currently building a Wordpress website whose navigation menu has items with long titles requiring a second line. However, some of the remaining items are only short words, and don't need to wrap onto a second line. I would like to make the single line items to vertically align in the middle of the menu, but at the moment they seem to stay at th...
Why are Woocommerce product names showing the word line [line] in square brackets after?
As the title suggests, can anyone please advise why Woocommerce is showing the word line in square brackets '[line]' after the product names? Please see the image below: I am using the latest version of WordPress (3.8.1), the Yith SoCute theme and Woocommerce with the following plugins: I think that there may be a simple explanation for this which ...
Second Text Line Above The First Line
I'm having an issue displaying a long title in a recent post widget of a wordpress site, because when the link is too long, it breakes to another line but this new line, is messing up with the first one, because the second line is above. I tried add this CSS line line-height: 1.6em; in .widgettitle li but didn't work and tried a couple of more cla...
Set max width for each line or insert a line break in a section of text in CSS
I have a h2 on a slider being populated from a Wordpress post title. Part of that title is a trademark, so I want that to be all on one line, with Welcome to on the line above. Currently I have... Welcome to The Happy Foundation I want... Welcome to The Happy Foundation Using max-width in css I can achieve... Welcome to The Happy Foundation or Welc...
line by line date dropdown select menu
I am trying to make a select dropdown box for my wordpress site. When i click, it will have 7 options of dates starting from the next day to 7 days from now. I have this code done, to get the current date and the days ahead. or How do i create a select menu. Where when i click it, The options are as such: Monday, 26 October 2015 Tuesday, 27 October...
jQuery AJAX post only finds first line of mult line textbox
I've got a POST form on WordPress that I'm using to pass data to MailChimp via its API. In and of itself (i.e. not using jQuery), it works as expected. However, when instead of using the form's action to navigate to a new page I try to pass the data via an AJAX post action, it only finds the first row of the multi line text box. FORM PAGE THAT PROC...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .