1

I'm building a very tiny web app based on Wordpress.

For this, I have created a custom post type for the items users will be able to manage in the app.

I have created a very pretty, optimized overview page as a frontend page. However, to save development time, editing each item still takes place in the backend.

Some operations in the backend - namely, deleting an item - take the user to the items overview page in the backend (/wp-admin/edit.php?post_type=my_item_post_type) rather than my pretty frontend page.

I would like to prevent this, so that when the user is taken to /wp-admin/edit.php?post_type=my_item_post_type they will be redirected to the pretty frontend page.

Is there a hook I can utilize for this?

1

1 Answer 1

1

OK, this, put in functions.php works for me, based on this question and answer:

/* Send users away from wp-admin/edit.php to page with ID 999
  for post type my_post_type */

add_filter( 'parse_query', 'filter_post_edit_screen' );

function filter_post_edit_screen($query) {
    global $pagenow;

    if (is_admin() && $pagenow=='edit.php' && $query->query["post_type"] == "my_post_type"){
     wp_redirect(get_permalink(999));
     exit;

    }
    return $query;
}

don't know whether it is clean to call wp_redirect() for this hook but don't see why not.

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.