• Resolved kcomphlint

    (@kcomphlint)


    We are using Relevanssi on an intranet we built. Some of our users wanted to ability to be redirected to the front-end of a page after making an edit (rather than staying in the editor view). The users that are using this function are not having their changes/edits indexed upon saving the page. Here is the function we are using:

    function checkEditUpdateRedirect( $post_id )
    {
        $accepted_statuses = ['publish', 'private'];
        if ( ! in_array( get_post_status( $post_id ), $accepted_statuses ) ) return;
        $user = wp_get_current_user();
        $redirectToFront = (int) get_field( 'redirect_after_edits', 'user_'. $user->ID );
        if ( $redirectToFront ) {
        	wp_redirect( get_permalink( $post_id ) );
            exit;
        }
    }
    add_action( 'save_post', 'checkEditUpdateRedirect' );

    I have tried triggering indexing before the wp_redirect, but nothing I am doing seems to be working. Any help or tips you can offer? At what point is the indexing triggered when a post is saved/updated? I seem to be bypassing it somehow.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yeah, you are: save_post is the second to last action to fire in the post saving process. After that comes wp_insert_post, which is where Relevanssi comes in to index the post (at priority 99).

    So, exiting in save_post, priority 10, will break everything that relies on wp_insert_post, not just Relevanssi, and also everything that uses save_post at a bigger priority.

    Change your action to wp_insert_post and use PHP_INT_MAX for the priority to make sure nothing else is running after your code. That should fix the problem.

    Thread Starter kcomphlint

    (@kcomphlint)

    Worked like a charm. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Issues with Indexing When Using Custom save_post function’ is closed to new replies.