alan-dague-greene
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Plugins
In reply to: [Co-Authors Plus] Order of authors not retainedCorrection: 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]; }
Forum: Plugins
In reply to: [Co-Authors Plus] Order of authors not retainedThis 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, intemplate-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!
- This reply was modified 8 years, 2 months ago by 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)