0

I have a function for a custom post type that redirects NEW posts to a specific url after they are submitted by users:

function tribe_redirect_after_community_submission( $wp ) {
    if ( isset( $wp->query_vars[WP_Router::QUERY_VAR] )
    && $wp->query_vars[WP_Router::QUERY_VAR] == 'ce-add-route'
    && !empty( $_POST ) ) {
        wp_safe_redirect(home_url('http://www.example.com'));
        exit();
    }
}

I want to expand upon this so that when a user UPDATES a post, the user gets redirected to a different url.

So just as I'm testing to see if $wp->query_vars[WP_Router::QUERY_VAR] is set to ce-add-route, I need to test against the possibility that it might be set to ce-edit-route.

How can I edit my function above to achieve that? I'm a novice with php and didn't write the function on my own.

UPDATE: I revised my function and have the ce-edit-route redirect working, however, the ce-add-route redirect is no longer working.

function tribe_redirect_after_community_submission( $wp ) {
    if ( isset( $wp->query_vars[WP_Router::QUERY_VAR] )
        && $wp->query_vars[WP_Router::QUERY_VAR] == 'ce-add-route'
        && !empty( $_POST ) ) {
        wp_safe_redirect(home_url('http://www.example.com/wptest/event-submitted/'));}
    elseif ( isset( $wp->query_vars[WP_Router::QUERY_VAR] )
        && $wp->query_vars[WP_Router::QUERY_VAR] == 'ce-edit-route'
        && !empty( $_POST ) ) {
        wp_safe_redirect(home_url('http://www.example.com/wptest/event-updated/'));
        exit();
    }
}

2 Answers 2

0

here's a plugin I wrote that handles and performs many redirects after Publish/Update. not sure if it's specific for what you're wanting to do, but might suit you in some other scenario(s).

http://crstauf.github.io/And-Then/

0

This is what I needed for both redirects to work correctly:

function tribe_redirect_after_community_submission( $wp ) {
    if ( isset( $wp->query_vars[WP_Router::QUERY_VAR] ) 
&& $wp->query_vars[WP_Router::QUERY_VAR] == 'ce-add-route' 
&& !empty( $_POST ) ) {
        wp_safe_redirect(home_url('http://www.myurlhere.com/event-submitted/'));
        exit();
    } elseif ( isset( $wp->query_vars[WP_Router::QUERY_VAR] ) 
&& $wp->query_vars[WP_Router::QUERY_VAR] == 'ce-edit-route' 
&& !empty( $_POST ) ) {
        wp_safe_redirect(home_url('http://www.myurlhere.com/event-updated/'));
        exit();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.