0

not sure if this is even possible (guessing it should be though)...

I have a custom taxomomy of status, containing the following terms...

pending, collecting, started, doing, dispatched, delivered, done

I would like to add all the posts attached to doing, dispatched, delivered to the archive of the started term using the pre_get_posts hook.

e.g Visiting example.com/status/started/ would display all posts with these attached terms

This is what I have (and is not working)...

add_action( 'pre_get_posts', 'tax_status_started_archive' );

function tax_status_started_archive( $query ) {

  if( $query->is_main_query() && !is_admin() && is_tax( 'status', 'started') ) {

    $tax_query = array(
      'relation' => 'AND',
      array(
        'taxonomy'         => 'status',
        'terms'            => array('started', 'doing', 'dispatched', 'delivered'),
        'field'            => 'slug',
        'operator'         => 'IN',
        'include_children' => false,         
      ),
    );

    $query->set( 'tax_query', $tax_query);

  }

}

Point of note: I'm aware I could group all of these posts under another 'catch-all' taxonomy term such as in-progress, this would require some reworking of previous code which I would like to avoid if possible

TIA Guys n' Gals 👍🏼

4
  • Try using 'relation' => 'OR' instead. But, shouldn't that mop_tax_status be status?
    – Sally CJ
    Aug 2 at 17:01
  • @SallyCJ ah thanks - will try that when I get in office tomorrow (thanks for the typo catch - applies to this post rather than the actual code - have now corrected) Aug 2 at 17:09
  • @SallyCJ - nope - 'fraid not - thank you for the idea though 👍🏼 Aug 4 at 13:38
  • Can you show your latest code, or did you just replace the 'relation' => 'AND', with 'relation' => 'OR', ? And by "is not working", did you mean that the started archive page doesn't include posts that are not in the started term, but are in the other status terms like doing? So if post A was in doing, but not in started, the post should still show on the started archive page and yet that didn't actually happen?
    – Sally CJ
    Aug 4 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.