Last active
          July 18, 2022 05:46 
        
      - 
      
 - 
        
Save mwhiteley16/af355c262381df5107261b79ca4e1004 to your computer and use it in GitHub Desktop.  
    Index FacetWP on Form Submission/Edit
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| /** | |
| * Ensure FacetWP indexes when events are created/edited forms domain | |
| */ | |
| add_action( 'af/form/submission', function ( $form, $fields, $args ) { | |
| if ( isset( AF()->submission['post'] ) ) { | |
| $post_id = AF()->submission['post']; | |
| FWP()->indexer->index( $post_id ); | |
| // tried to reindex all, same result | |
| // FWP()->indexer->index(); | |
| } | |
| }, 20, 3 ); | |
| // ANOTHER ATTEMPT | |
| add_filter( 'af/form/editing/post_data', function ( $post_data, $form, $args ) { | |
| if ( $form['key'] !== 'form_62c59a4801f0b' ) { | |
| return $post_data; | |
| } | |
| FWP()->indexer->index( $post_data['ID'] ); | |
| // tried to reindex all, same result | |
| // FWP()->indexer->index(); | |
| return $post_data; | |
| }, 10, 3 ); | |
| // ATTEMPT # 3 | |
| add_action( 'af/form/editing/post_updated/key=form_62c59a4801f0b', 'wd_facetwp_index_on_event_update', 10, 3 ); | |
| add_action( 'af/form/editing/post_created/key=form_62c59a4801f0b', 'wd_facetwp_index_on_event_update', 10, 3 ); | |
| function wd_facetwp_index_on_event_update( $post, $form, $args ) { | |
| // reindex FacetWP to ensure updated/created event is indexed properly | |
| FWP()->indexer->index( $post->ID ); | |
| // also attemped a full reindex to no avail | |
| FWP()->indexer->index(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Hi @mwhiteley16,
I wonder if something as simple as this will do it: