I’m trying to set up some post permissions using taxonomies and I'm applying my rules in a pre_get_posts action.

It’s working fine when multiple posts are found, but in class-wp-query.php near line 2060, it’s specifically not applying the tax_query rules when is_singular is true.

Is there a way around this without modifying core?

  • See this question, it has two solutions. Also, there was a ticket on the WordPress Trac which was set to wontfix. – Max Yudin Jun 8 '18 at 8:21
  • please share your code – honk31 Jun 8 '18 at 13:27
  • What tax_query do you want to use exactly? Could you show your code? – Krzysiek Dróżdż Jul 30 '18 at 12:42

You can always use posts_clauses filter and add processing for tax_query in there (you don't even need to write your own SQL):

function filter_single_with_tax_queries( $clauses, $query ) {
    global $wpdb;

    if ( $query->is_singular ) {  
        $query->parse_tax_query( $query->query_vars );
        $tax_clauses = $query->tax_query->get_sql( $wpdb->posts, 'ID' );
        $clauses['join'] .= $tax_clauses['join'];
        $clauses['where'] .= $tax_clauses['where'];
    return $parts;
add_action( 'posts_clauses', 'filter_single_with_tax_queries', 10, 2 );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.