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.

Doesnt Show Any Results

<?php

$query = array(
    'tax_query' => array(

        'relation' => 'AND',

        array (
            'taxonomy' => 'location',
            'field' => 'slug',
            'terms' => array( 'california', '' ),
        ),

        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => array( 'comedy', '' ),
        )
    )
);


$query = new WP_Query();


?> 

Doesnt Show Any Results :( No Posts are displayed, Need Help thanks

share|improve this question

3 Answers 3

I'm not sure what the rest of your code looks like, but you are mixing up your $query variable and you are not sending your $query to the new instance of WP_Query. Also, there is no need to send an array to the "terms" parameter if you are only using one term. Try this.

<?php
// Set the args
$args = array(
    'tax_query' => array(
        'relation' => 'AND',
        array (
            'taxonomy' => 'location',
            'field' => 'slug',
            'terms' => 'california',
        ),
        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => 'comedy',
        )
    )
);

// Make a new instance of WP_Query
$query = new WP_Query();

// Make the query
$query->query($args);

// Test for posts
if($query->have_posts())
{
    // Loop through posts
    while($query->have_posts())
    {
        // Set up the post
        $query->the_post();
        global $post;
    }
}
?>
share|improve this answer
    
Im getting an error Warning: Missing argument 1 for WP_Query::query(), called in C:\xampp\htdocs\artwp\wp-content\themes\artwp\shows.php on line 49 and defined in C:\xampp\htdocs\artwp\wp-includes\query.php on line 2901 –  adolfozen Aug 22 '11 at 20:59
    
Of course you did! That's because I put the $args in the wrong place. I've updated my answer. Try it again. –  tollmanz Aug 22 '11 at 21:42
    
i tried the code above doesnt show results also but, when i tried –  adolfozen Aug 23 '11 at 4:32
    
<?php $args = array( 'tax_query' => array( 'relation' => 'AND', array ( 'taxonomy' => 'location', 'field' => 'slug', 'terms' => 'california', ), array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'comedy', ) )); $query = new WP_Query($args); $query->query('showposts=5'); if($query->have_posts()) { while($query->have_posts()) { echo '<div>'; the_title(); echo '</div>'; $query->the_post();global $post; }} ?> works but its showing also the posts from the post type posts –  adolfozen Aug 23 '11 at 4:37
    
Can you pastebin your code? –  tollmanz Aug 23 '11 at 4:37

Well first of all you are using it wrong.

$query = new WP_Query(array(
     'post_type' => 'post,'
     'post_status' => 'publish',
     'tax_query' => array(
        'taxonomy' => 'genre',
        'field' => 'slug',
        'terms' => array( 'comedy', '' ),
    )
));

The array needs to be supplied to the WP_Query object. Also, I am pretty sure atleast one post type needs to be specified for it to work.

share|improve this answer
    
@Chris...doesn't post_type default to "post" and post_status default to "publish". I've not tried it without setting these values, but I believe these are the defaults. –  tollmanz Aug 22 '11 at 15:15
    
Technically they are defaults, but I have encountered situations where the query will return no results if a post_type is not specified. Post status is not required. –  Chris Aug 28 '11 at 1:13
<?php
// Set the args
$args = array(
    'tax_query' => array(
        'post_type' => 'show',
        'relation' => 'AND',
        array (
            'taxonomy' => 'location',
            'field' => 'slug',
            'terms' => 'california',
        ),
        array(
            'taxonomy' => 'genre',
            'field' => 'slug',
            'terms' => 'comedy',
        )
    )
);




 // Make a new instance of WP_Query
$query = new WP_Query($args);

// Make the query
$query->query('showposts=5');

// Test for posts
if($query->have_posts())
{
    // Loop through posts
    while($query->have_posts()) 
    {
    echo '<div>';
  the_title();
    echo '</div>';

        // Set up the post
       $query->the_post();


        global $post;


    }
}



?>

But the problem is it shows the posts also from posts

Result: is something like California (Comedy) Posts Then the rest posts from the POSTS TYPE Post1 Post 2

share|improve this answer

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.