• This is on WordPress 2.8.

    I cannot exclude posts using an array of post id’s because post__not_in does not work. I tried looking through the wp-includes/query.php to try and fix it on my own with no luck. Anyone been able to clean this up?

Viewing 13 replies - 16 through 28 (of 28 total)
  • Thread Starter virtuexru

    (@virtuexru)

    Well my current query is this:

    $args_fp = array(
    	'post_type' => 'post',
      	'post_status' => 'publish',
      	'posts_per_page' => 8,
    	'post__not_in' => array(343, 206),
      	'caller_get_posts'=> 1
    );
    $fp_query = null;
    $fp_query = new WP_Query($args_fp);

    Still, no category 4 exclusion, and the wrong post ID exclusion. Gotta be a filter or another query somewhere.

    Thread Starter virtuexru

    (@virtuexru)

    I have another query on the page but it’s just to get 1 sticky post:

    global $post;
    $sticky = get_option('sticky_posts');
    $args   = array(
    	'posts_per_page' => 1,
    	'post__in'  => $sticky,
    	'caller_get_posts' => 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);

    OK. Just as an experiment, remove any filters just ahead of the creation of $fp_query and print out the query request after.

    $args_fp = array(
    	'post_type' => 'post',
      	'post_status' => 'publish',
      	'posts_per_page' => 8,
    	'post__not_in' => array(343, 206),
      	'caller_get_posts'=> 1
    );
    remove_all_filters('posts_where');
    remove_all_filters('posts_join');
    $fp_query = null;
    $fp_query = new WP_Query($args_fp);
    echo "<p>REQUEST:$wp_query->request</p>";
    Thread Starter virtuexru

    (@virtuexru)

    Looks almost identical:

    REQUEST: SELECT SQL_CALC_FOUND_ROWS wp_16_posts.* FROM wp_16_posts WHERE 1=1 AND wp_16_posts.ID NOT IN (261,209) AND wp_16_posts.ID NOT IN ( SELECT tr.object_id FROM wp_16_term_relationships AS tr INNER JOIN wp_16_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = ‘category’ AND tt.term_id IN (‘4’, ‘0’, ‘0’) ) AND wp_16_posts.post_type = ‘post’ AND (wp_16_posts.post_status = ‘publish’) ORDER BY wp_16_posts.post_date DESC LIMIT 0, 8

    I may be brain dead. Instead of echoing $wp_query->request, please try $fp_query->request.

    Thread Starter virtuexru

    (@virtuexru)

    @vtxyzzy – That’s what I did, echoing out wp_query gave nothing so I used fp_query instead.

    OK. Something is stepping on your query. You will have to search for code that excludes category id 4, whatever category that is. Also, see what is unique about posts 261 and 208. Maybe that can help find the other query.

    The only other suggestion I can think of is to try using $xx_query as the name instead of $fp_query. If that gives the same $xx_query->request, it has to be a filter, maybe in a plugin.

    Thread Starter virtuexru

    (@virtuexru)

    @vtxyzzy – If it’s a filter in some other plugin I’m going to have to look through about 45 plugins :\. Is there any way to just make sure the query is being started from scratch? wp_reset_query?

    If it really is a filter, then the remove_all_filters code I suggested earlier should have taken care of it. I am at a loss to explain it. Did using $xx_query instead of $fp_query make any difference?

    And yes, wp_reset_query is worth a try.

    Depends what the filter is on, the above code will only remove filters on two hooks.

    pre_get_posts would be another possible place for a filter/action.

    You could try this to see if there’s anything hooked onto pre_get_posts.

    $f = ( isset( $wp_filter['pre_get_posts'] ) ) ? $wp_filter['pre_get_posts'] : 'nothing';
    print '<pre>';
    print_r( $f );
    print '</pre>';

    If you see the nothing text, there’s no filter/action on pre_get_posts.

    NOTE: parse_query would be another hook to check.

    The code below will print all filters that contain keywords in their name:

    <?php
    global $wp_filter;
    $keywords = array('post','query');  // Keywords to find
    echo '<p>FILTERS:';
    foreach (array_keys($wp_filter) as $key) {
      foreach ($keywords as $keyword) {
        if (false !== strpos($key,$keyword)) {
          $val = $wp_filter[$key];
          echo "<p>KEY: $key<br /> "; print_r($val);echo '</p>';
        }
      }
    }
    echo '</p>';
    ?>

    Hello ! can anyone help me whit “post_not_in” array ??

    I would to exclude the current category , but not the parent of current.

    this is the example:

    ?php $categories = get_the_category($post->ID);
    
      if ($categories) { $category_ids = array();   
    
    foreach($categories as $individual_category)
    
    $category_ids[] = $individual_category->term_id;
    
        $args=array(
    
            'category__in' =>  $category_ids,
    
    	'post__not_in' => array($post->ID),
    
            'showposts'=>5, // Corresponds to Number of related posts to be shown.
    
            'caller_get_posts'=>1
    
        );
    
     $my_query = new wp_query($args);
    
    if( $my_query->have_posts() ) {
    
    echo '<h2 class="related_post_title">OTHER VIDEOS FROM </h2><ul class="related_post">'; 
    
    while ($my_query->have_posts()) {
    
    $my_query->the_post();?> 
    
    <li><a href="<?php the_permalink() ?>"
    
    rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <img src="<?php echo get_post_meta($post->ID, "video_thumbnail", true); ?>" alt="<?php the_title(); ?>" /><?php the_title(); ?></a></li><?php }
    
    echo '</ul>'; } } $post = $backup; wp_reset_query(); ?>

    this is work right…but gets me the relative of category parent and not only the child!

    please help meee 🙂

Viewing 13 replies - 16 through 28 (of 28 total)

The topic ‘‘post__not_in’ variable for wp_query does not work..’ is closed to new replies.