Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Correction: don’t use &$coauthor when iterating over the terms, otherwise there will be problems with multiple authors.

    foreach($coauthor_terms as &$coauthor_term) {
      $coauthor_term->order = $author_order_data_ids[$coauthor_term->term_id];
    }

    This appears to be an issue with WordPress 4.7 core, not the plugin. get_the_terms() in 4.7 does not return terms in the right order.

    Here’s a fix I’ve implemented in the get_coauthors() function, in template-tags.php in the plugin source.

    
    // Starting on line 19 in the current version
    if ( is_array( $coauthor_terms ) && ! empty( $coauthor_terms ) ) {
      
      // Collect all author term IDs
      $term_ids = array_map(function($el){
        return $el->term_id;
      }, $coauthor_terms);
      
      // Get order of term IDs for this post
      $sql_get_author_order = sprintf(
        "SELECT term_taxonomy_id, term_order
        FROM %s
        WHERE object_id = %d
        AND term_taxonomy_id IN (%s)
        ORDER BY term_order ASC",
        $wpdb->term_relationships,
        $post_id,
        join(', ', $term_ids)
      );
      
      // Organize order by term ID
      $author_order_data = $wpdb->get_results($sql_get_author_order);
      if(!empty($author_order_data)) {
        $author_order_data_ids = [];
        foreach($author_order_data as $order_data) {
          $author_order_data_ids[$order_data->term_taxonomy_id] = $order_data->term_order;
        }
        
        foreach($coauthor_terms as &$coauthor) {
          $coauthor->order = $author_order_data_ids[$coauthor->term_id];
        }
      }
      
      // Sort authors by order
      usort($coauthor_terms, function($a, $b){
        return ((int) $a->order > (int) $b->order) ? 1 : -1;
      });
      
      foreach ( $coauthor_terms as $coauthor ) {
    // ...
    

    Hopefully 4.7.1 will fix this and render this hack obsolete!

    Thread Starter alan-dague-greene

    (@alan-dague-greene)

    Thanks for your help, I’m getting the right image now, but it’s still not coming in at the right size. I’ll report back if I figure anything out.

Viewing 3 replies - 1 through 3 (of 3 total)