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.

After spending most of the day looking for solutions and trying them out, I decided to explain my problem here.

I am aware that this subject has been covered and as you will see I am using code that has been suggested here and over at ottopress, but I still cannot figure it out.

I have a custom post type called 'review' (non-hierarchical) I have a custom taxonomy called 'reviewcats' (hierarchical) I have a whole bunch of terms under the taxonomy of which 3 are main and the rest children:

  • featured
  • applications (containing children)
  • games (containing children)

On my homepage template I am first showing the latest review (custom post type) that has the term 'featured' from the 'reviewcats' taxonomy. That review also contains the terms 'applications' and a child thereof.

Under the Feature I would like to show the 10 most recent reviews (custom post type), but not the one from above, the one with the term 'featured'

I have been trying with the code below (and many variations of it), but cannot get it right. Can anyone shed light on this dark matter for me please? Much appreciated!

$recentapps_query['tax_query'] = array(
                'relation' => 'AND',
                array(
                    'post_type' => 'review',
                    'post_status' => 'publish',
                    'posts_per_page' => 10,
                ),
                array(
                    'taxonomy' => 'reviewcats',
                    'terms' => array('featured'),
                    'field' => 'slug',
                    'operator' => 'NOT IN',
                ),
            );
            query_posts($recentapps_query);

if needed, the sandbox site is http://senl.in/jOaalP

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Firstly, your tax query is a little jumbled. The first nested array should actually be at the 'root' of your query_posts() argument, with tax_query as a key among them;

array(
    'post_type' => 'review',
    'post_status' => 'publish',
    'posts_per_page' => 10,
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'reviewcats',
            'terms' => array( 'featured' ),
            'field' => 'slug',
            'operator' => 'NOT IN',
        )
    )
);

However, forgive me if I'm mistaken, but I think your query could be a lot simpler - simply exclude the 'featured' review you've just grabbed;

query_posts( array(
    'post_type' => 'review',
    'post_status' => 'publish',
    'post__not_in' => array( $post->ID ) // $post *should* be the featured review, since it was the last post queried/worked on 
) );
share|improve this answer
    
just beat me to it, Just a Note: and since its not the main query you should use WP_query or get_posts and not query_posts. –  Bainternet Jun 7 '11 at 13:19
    
@TheDeadMedic thanks for your input, very possible that things are getting jumbled on my end, been staring at the code and changing it around a bit too often today I think... Anyways both your samples don't work. I started with your 2nd suggestion as it made sense, but that didn't work at all: errors. Then I tried the first one and it also gives me errors. Perhaps it is better to see the whole picture? I therefore have pasted part of my homepage.php file here: senlin.pastebin.ca/2076198 @Bainternet, tried it too with your suggestion, but didn't seem to make any difference –  Piet Jun 7 '11 at 14:27
    
no other input on this? guess I will have to start over from scratch to figure it out... will post a working solution once i have accomplished it. –  Piet Jun 8 '11 at 3:55
1  
Okay, check it out - senlin.pastebin.ca/2076755 - You had quite a few HTML nesting errors, and the troublemaker was that you were resetting the query after the featured app, thus overwriting the $post used for excluding from recent apps. –  TheDeadMedic Jun 8 '11 at 14:02
1  
terrific @TheDeadMedic! You nailed it and I learned a lot! there was one typo on line 68 so the final version is senlin.pastebin.ca/2077121 Thanks so much for solving this for me! –  Piet Jun 9 '11 at 4:06
show 1 more 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.