• Resolved Fibro Jedi

    (@fibrojedi)


    Hey!

    Right, for a start there is a high likelihood that the issue is with my Custom Post Type and not RankMath, but I can’t figure out the cause, so I hope you’ll help.

    Something is clashing in terms of the permalink and custom fields of my Custom Post Type and Rank Math.

    I’ve uploaded screenies here:

    View post on imgur.com

    The top permalink is the correct one. What RankMath is loading is the permalink for one of the items in a custom post type.

    • The post in question has a post_type of ‘post’ not the CPT
    • If I now saved the affected post, it will take on the permalink in the RankMath preview not the one in the permalink at the top.

    Any idea what might cause this? I’ve done my best so far to dig into my code (not that it’s complicated) – and if I find the cause before you have a chance to reply I’ll close this thread. But it’s really bizarre and, if I’m not careful, I end up moving high-traffic content to an incorrect URL until I spot it and reverse it.

    As I said, I’m not blaming RankMath, it’s just that’s where I see the symptom – but it may not be the cause.

    Thanks in advance!

    FJ

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @fibrojedi,

    Thank you for contacting the support.

    Can you please confirm if you are duplicating your posts instead of creating a new one manually?

    Looking forward to helping you.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    No, I have no need to duplicate posts. The one in question is updated every year, but always on the same URL.

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @fibrojedi,

    Assuming you are using the latest version of all the plugins and the themes (please update if not yet), it would seem like a conflict with one of the plugins or the theme you are using.

    To determine that, please follow this troubleshooting guide:
    https://rankmath.com/kb/check-plugin-conflicts/

    Here is a video you can follow as well:

    Only the site admin would know and your users won’t be affected by this troubleshooting.

    Let us know how that goes. Looking forward to helping you.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Hey,

    Oh, it definitely will be. The problem is that it’s a CPT that I’ve developed a mini plugin for. But I couldn’t see anything in my code that could have had that effect on a non-CPT post.

    I’ll have to keep looking. Since I resaved the CPT posts, the issue hasn’t come up, but that’s not the same as having identified and fixed it! I’ll get back to you if/when other questions crop up.

    Thanks,

    FJ

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @fibrojedi,

    Let us know if the issue appears again so we can investigate this further.

    Please don’t hesitate to get in touch in case you need our assistance with anything else in the meantime.

    Thank you.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Yes, it’s happening constantly at the moment and I cannot figure out why. I’ve tried all sorts of tweaks/changes.

    My current save post function is (showing just saving one custom field)

    function mounts_save_data($post_id){
     if(!isset($_POST['post_type']) || $_POST['post_type']!= "custom_type"){
          return;
       }
       /* extra checks */
       if($post->post_type !== 'custom_type'){
         return;
       }
      if(isset($_POST['mounts_year'])){
       update_post_meta($_POST['post_ID'], 'mounts_year', $_POST['mounts_year']);
      }
      return $post_id;
    }
    add_action('save_post_custom_type','mounts_save_data',101,2); // to be ahead of RankMath's update_post_info()

    The last line did not help or hinder the process.

    What happens when I save a custom post type is that RankMath then takes the slug of the CPT and then applies it to another post that is not a CPT.

    I’ve checked

    • The post_ID is correct before update_post_meta() is triggered
    • $_POST['post_ID'] and $post->post_id and $post_id agreed. They did.
    • Deleting a CPT and recreating it did not fix it.
    • The value saved on the CPT but also on other posts. The URL slug changed on at least two other posts within the RankMath panel.

    NB: the slug is not automatically saved as wrong, but when a non-CPT post is edited, the RankMath preview shows the slug of the CPT, which then gets saved if the post is saved (and if I haven’t manually changed it back).

    • This reply was modified 2 years, 5 months ago by Fibro Jedi. Reason: Extra details added
    Thread Starter Fibro Jedi

    (@fibrojedi)

    I’m going to try your plugin approach for disabling plugins just for admin. I even made a new function to ONLY save that one field and the same behaviour occurred.

    function mounts_save_data_NEW($post_id, $post){
      // bail out if this is an autosave
         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
             return;
         }
    
         // bail out if this is not an event item
         if ( 'custom_type' !== $post->post_type ) {
             return;
         }
         if(isset($_POST['mounts_year'])){
           update_post_meta($post_id, 'mounts_year', $_POST['mounts_year']);
         }
    }
    add_action('save_post_custom_type','mounts_save_data_NEW',10,3);

    The only other symptom (as well as the Rank Math panel showing the wrong slug) is that the above field also saves on other non-CPT posts, which it shouldn’t, so something else is messed up somewhere.

    Oddly, this doesn’t occur on my localhost version of my site but does on the live one. I’ll try your admin-plugin-disable thing and see what comes out the other end.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Well that didn’t work. I enabled the troubleshooting mode, got redirected to the dashboard, did a log out and back in…and nothing had changed.

    So your plugin is incompatible with my site, apparently. I’ll find another way.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Right, I have found the cause – and as I said in my first opening post, it wasn’t caused by RankMath. I’ve turned off the thing causing it as it’s not a high-priority feature. But it means this thread is closed – sorry for bothering you all with it.

    Thanks.

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @fibrojedi,

    We are glad that you were able to resolve the issue. If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Help! Conflict with CPT permalink’ is closed to new replies.