Ready to get started?Download WordPress


Co-Authors Plus
Can't query posts for category and author together (1 post)

  1. Gozlingo
    Posted 3 years ago #

    I've noticed that it's not possible to query for categories and authors at the same time.

    When searching for a category, the generated SQL makes INNER JOINs on the "term_relationships" and the "term_taxonomy" tables twice (once for the category and once for the authors). This doesn't work!

    I've made a slight change to the SQL in the plugin to use aliases on the joins which fixes the problem.

    I've changed line 171 in co-authors.php:

    $join .= " INNER JOIN $wpdb->term_relationships AS coauthor_relationships ON ($wpdb->posts.ID = coauthor_relationships.object_id) INNER JOIN $wpdb->term_taxonomy AS coauthor_taxonomy ON (coauthor_relationships.term_taxonomy_id = coauthor_taxonomy.term_taxonomy_id)";

    and then line 186:

    $where = preg_replace('/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(\d+))/', '($1 OR (coauthor_taxonomy.taxonomy = \''. $this->coauthor_taxonomy.'\' AND coauthor_taxonomy.term_id = \''. $term->term_id .'\'))', $where, 1); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND

    Hope that helps if anyone else was having the same problem.



Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic