Custom-Posttype & Custom Taxonomy WP_Query

I add a custom post type with custom taxonomy and i wish to get all postings into this by a template, but the result is 0

$args=array(
  'post_type' => 'contents',
  'post_status' => 'publish',
  'tax_query' => array(
      'taxonomy' => 'content-category',
      'field' => 'id',
      'terms' => array(5,26,28)
  ),
  'meta_key' => 'fs16'
);
$query = new WP_Query($args);

The SQL-Query is followed (don’t know why):

Read More
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) JOIN wp_icl_translations t ON wp_posts.ID = t.element_id AND t.element_type = 'post_contents' JOIN wp_icl_languages l ON t.language_code=l.code AND l.active=1 WHERE 1=1 AND 0 = 1 AND wp_posts.post_type = 'contents' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_key = 'fsk16' ) AND t.language_code='en' GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10

What’s going wrong here?

Related posts

Leave a Reply

2 comments

  1. The taxonomy, field and terms in tax_query should be two array-level deep instead of one. Quoted from the WP_Query page:

    Important Note: tax_query takes an array of tax query arguments arrays
    (it takes an array of arrays) – you can see this in the second example
    below. This construct allows you to query multiple taxonomies by using
    the relation parameter in the first (outer) array to describe the
    boolean relationship between the taxonomy queries.

    So, your arguments shoud be like:

    $args = array(
        'post_type' => 'contents',
        'tax_query' => array(
            array(
                   'taxonomy' => 'content-category',
                   'field' => 'id',
                   'terms' => array(5,26,28)
            )
        ),
            'meta_key' => 'fs16'
    );
    

    You may omit 'post_status' => 'publish' since it’s the default value used anyway.

  2. Are you sure you want to pass so many arguments?
    The following should be sufficient to just display the posts of that category.

    $args = array( 'post_type' => 'contents', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
        the_title();
        echo '<div class="entry-content">';
        the_content();
        echo '</div>';
    endwhile;
    

    The above code is taken from the WP Codex.