Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 84a4f9a

Browse files
committed
Fix post field partial from erroneously selecting nested post placements
1 parent d87ff82 commit 84a4f9a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

js/customize-post-field-partial.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@
167167
api.preview.send( 'focus-control', settingId + '[' + partial.params.field_id + ']' );
168168
},
169169

170+
/**
171+
* Find all placements for this partial in the document.
172+
*
173+
* Fixes issue where selector can match too many elements when post loops are nested inside other posts.
174+
*
175+
* @return {Array.<Placement>} Placements.
176+
*/
177+
placements: function() {
178+
var partial = this, placements;
179+
placements = api.selectiveRefresh.partialConstructor.deferred.prototype.placements.call( this );
180+
181+
// Remove all placements whose closest .hentry is not for this post.
182+
placements = _.filter( placements, function( placement ) {
183+
var closestHentry = placement.container.closest( '.hentry' );
184+
return ! closestHentry.length || closestHentry.hasClass( 'post-' + String( partial.params.post_id ) );
185+
});
186+
187+
return placements;
188+
},
189+
170190
/**
171191
* @inheritdoc
172192
*/

0 commit comments

Comments
 (0)