Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to grab posts of post type "leads" (see below for the code I am using) however the query produced (obtained via debug queries) is including the clause 'where post_type in ("leads", "leads", "product_description", "custom_products")' [[notice leads is there twice]]

This leads me to think that somehow something is being hooked into this -- but shouldn't suppress_filters => true prevent this from happening? If that is the case what exactly is going on and how do I limit posts to just "leads" ?

  $args = array(
      'numberposts' => 5,
      'order' => 'DESC',
      'orderby' => 'date',
      'post_type' => 'leads',
      'post_status' => 'publish',
      'post__not_in' => array($post->ID),
      'suppress_filters' => true
  );
  $result = get_posts($args);
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I built a workaround for now, but would really love to know what is causing this. The workaround was obtained by removing changing "suppress_filters" to true and then adding a function that adds to the where clause of the SQL...

But I would rather know how to fix this at the root rather than a bandaid

My workaround was accomplished by adding the following to my functions.php:

function leads_post_type_where( $where ) {
$clause = "";
$post_types=get_post_types($args,'names');
foreach ($post_types as $post_type ) {
    if (trim($post_type)!="" && trim($post_type) != "ditl_post") {
        if ($clause==""){
            $clause .= "'$post_type'";
        } else {
            $clause .= ", '$post_type'";
        }
    }
}   

$where .= ' AND post_type NOT IN ('.$clause.')';
return $where;
}

Then updated my get_posts call to:

$args = array(
      'numberposts' => 5,
      'order' => 'DESC',
      'orderby' => 'date',
      'post_type' => 'leads',
      'post_status' => 'publish',
      'post__not_in' => array($post->ID),
      'suppress_filters' => false
  );
    add_filter( 'posts_where', 'leads_post_type_where' );
    $result = get_posts($args);
    remove_filter( 'posts_where', 'leads_post_type_where' );
share|improve this answer
add comment

Your Answer

 
discard

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.