Title: 404 error solution
Last modified: January 3, 2019

---

# 404 error solution

 *  Resolved [pablobablo](https://wordpress.org/support/users/pablobablo/)
 * (@pablobablo)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/404-error-solution/)
 * Hi!
    To fix 404 error I’ve made a fix in the custom_permalinks_original_post_link
   method. File custom-permalinks/frontend/class-custom-permalinks-frontend.php.
 * It works.
 *     ```
         public function custom_permalinks_original_post_link( $post_id ) {
   
           remove_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
           remove_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
   
           require_once ABSPATH . '/wp-admin/includes/post.php';
           list( $permalink, $post_name ) = get_sample_permalink( $post_id );
   
           // START FIX ERROR 404
           global $wpdb;
           $existing_post_name = $wpdb->get_var( "SELECT post_name FROM {$wpdb->posts} WHERE ID = " . ((int)$post_id ) );
           if( $existing_post_name )
             $post_name = $existing_post_name;
           // END FIX
   
           $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
           $permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
   
           add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
           add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
   
           return $permalink;
         }
       ```
   
    -  This topic was modified 7 years, 5 months ago by [pablobablo](https://wordpress.org/support/users/pablobablo/).
    -  This topic was modified 7 years, 5 months ago by [pablobablo](https://wordpress.org/support/users/pablobablo/).
    -  This topic was modified 7 years, 5 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Sami Ahmed Siddiqui](https://wordpress.org/support/users/sasiddiqui/)
 * (@sasiddiqui)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/404-error-solution/#post-11050777)
 * [@pablobablo](https://wordpress.org/support/users/pablobablo/) What’s the error
   you were facing?
 * Thanks for sharing the solution.
 * Regards,
    Sami
 *  Plugin Author [Sami Ahmed Siddiqui](https://wordpress.org/support/users/sasiddiqui/)
 * (@sasiddiqui)
 * [7 years ago](https://wordpress.org/support/topic/404-error-solution/#post-11603172)
 * [@pablobablo](https://wordpress.org/support/users/pablobablo/) As I have not 
   got any response from you so just marking this thread as resolved without making
   any change.
 * Sami

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘404 error solution’ is closed to new replies.

 * ![](https://ps.w.org/custom-permalinks/assets/icon.svg?rev=1785367)
 * [Custom Permalinks](https://wordpress.org/plugins/custom-permalinks/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-permalinks/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-permalinks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-permalinks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-permalinks/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Sami Ahmed Siddiqui](https://wordpress.org/support/users/sasiddiqui/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/404-error-solution/#post-11603172)
 * Status: resolved