• Resolved Michael

    (@migaweb)


    I have the following setup:
    * custom post type custom-post
    * and a rewrite rule to link `/custom-post/demo’ to a special page:

    
    function rewrite_rules() {
     $postName = "custom-post";
     $postId = 123;
     
     add_rewrite_rule(
       $postName.'/?([^/]*)/', // also tried: '(?!.*elementor)'.$postName.'/?([^/]*)/?$',
       'index.php?page_id=' . $postId.'&pid=$matches[1]&ptype='.$postName,
       'top'
     );
    }
    add_action('init', 'rewrite_rules');
    

    Those parts work fine but I have trouble opening the custom post Elementor editor. When it opens
    https://localhost/~test/wp-admin/post.php?post=1786&action=elementor by clicking on “edit with Elementor” it will try to open https://localhost/~test/custom-post/demo/?elementor-preview=1786&ver=1658094603. It fails with the error that it can’t find the_content.
    I’m using a custom theme and the theme pages do have the_content() included.

    Is there a way to prevent the Elementor editor to follow that add_rewrite_rule? I’ve tried to use '(?!.*elementor)'.$postName.'/?([^/]*)/?$' as a rule and in my regex tests it will only match the frondend URL

    
    https://localhost/~test/custom-post/demo/
    https://localhost/~test/custom-post/demo/?elementor-preview=1786&ver=1658094603
    

    and not the elementor-preview URL but the editor still tries to follow the rule. If I remove the rule the Elementor editor will open correctly. So I would like to use that rule only for the frontend and make the backend ignore it.

    • This topic was modified 2 years, 4 months ago by Michael. Reason: fixing styling
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom URL rewrite breaks post editor’ is closed to new replies.