Skip to content

Commit

Permalink
Ensure P2P init hook was invoked before indexing.
Browse files Browse the repository at this point in the history
Fix a case where P2P connexions are not registered when trying to
index P2P facets. This is due to FacetWP ajax handler running its
actions on "init" hook which come before P2P has the chance of running
its action "p2p_init".

A check has been added in the two custom index processor to trigger
the P2P hook if it didn't already run.
  • Loading branch information
petitphp committed Oct 5, 2021
1 parent ef6d5b5 commit 7d3ab68
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions facetwp-p2p.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ public function p2p_indexer( $bypass, $defaults ) {
return $bypass;
}

// Ensure P2P init hook was invoked.
if ( ! did_action( 'p2p_init' ) ) {
do_action( 'p2p_init' );
}

$connexion = $source[1];
$connexion_side = $source[2];
$post_ptype = get_post_type( (int) $params['post_id'] );
Expand Down Expand Up @@ -299,6 +304,11 @@ public function p2pmetas_indexer( $bypass, $defaults ) {
return $bypass;
}

// Ensure P2P init hook was invoked.
if ( ! did_action( 'p2p_init' ) ) {
do_action( 'p2p_init' );
}

$connexion = $source[1];
$field_name = $source[2];
$post_id = (int) $params['post_id'];
Expand Down

0 comments on commit 7d3ab68

Please sign in to comment.