Skip to content

Instantly share code, notes, and snippets.

@bookchiq
Created October 11, 2018 20:07
Show Gist options
  • Save bookchiq/d542ce1ee70174a5dc9a7bd11e22af98 to your computer and use it in GitHub Desktop.
Save bookchiq/d542ce1ee70174a5dc9a7bd11e22af98 to your computer and use it in GitHub Desktop.
The WordPress plugin "Fix Duplicates" [ https://wordpress.org/plugins/fix-duplicates/ ] tests for duplication by title. In my situation, we'd inadvertently double-imported some posts, but had a lot of different posts with the same titles, so I needed a way to see which ones were truly duplicates (based on having the same timestamp) vs. just the …
jQuery( 'table.wp-list-table.widefat.fixed.posts tr' ).css( 'display', 'table-row' );
jQuery( 'tbody[id^="fix-duplicates-group-"]' ).each( function() {
var rowWrapper = jQuery( this );
var matchingDateCount = 0;
var dates = new Array();
var matchedDates = new Array();
var dateCount = rowWrapper.find( 'tr td.date abbr' ).length;
rowWrapper.find( 'tr td.date abbr' ).each( function() {
var currentDate = jQuery( this ).text();
if ( -1 !== dates.indexOf( currentDate ) ) {
matchingDateCount++;
matchedDates.push( currentDate );
} else {
dates.push( currentDate );
}
});
// Color sections where all dates match
if (
0 < matchingDateCount &&
dateCount === ( 1 + matchingDateCount )
) {
rowWrapper.find( 'tr' ).css( 'background-color', 'deepskyblue' );
} else if ( 0 < matchingDateCount ) {
for ( i = 0; i < matchedDates.length; i++ ) {
rowWrapper.find( 'tr td.date abbr:contains(' + matchedDates[i] + ')' ).each( function() {
jQuery( this ).css( 'background-color', 'orange' );
});
}
} else {
rowWrapper.find( 'tr[class^="duplicate-group-"]' ).css( 'display', 'none' );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment