Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto sync parent terms #3145

Merged
merged 6 commits into from
Jan 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Auto sync parent terms
  • Loading branch information
MARQAS committed Nov 22, 2022
commit 76bc4c8eca668133f47cdc519d25d2bb10ef4d09
8 changes: 8 additions & 0 deletions includes/classes/Indexable/Post/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ public function action_edited_term( $term_id, $tt_id, $taxonomy ) {
// Find ID of all attached posts (query lifted from wp_delete_term())
$object_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );

// If the current term is not attached, check if the child terms are attached to the post
if ( empty( $object_ids ) ) {
$child_terms = get_term_children( $term_id, $taxonomy );
if ( ! empty( $child_terms ) ) {
$in_id = join( ',', array_fill( 0, count( $child_terms ), '%d' ) );
$object_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ( $in_id )", $child_terms ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
}
}
if ( ! count( $object_ids ) ) {
return;
}
Expand Down