Support

Account

Home Forums Backend Issues (wp-admin) Retrieve post_ID in divi theme visual builder Reply To: Retrieve post_ID in divi theme visual builder

  • Alright, I do have a hacky solution for that. Not bulletproof, though working.

    $_POST and $_GET of those AJAX calls unfortunately do not contain any ID-related info (no ‘et_post_id’). But I’ve noticed that Divi Pagebuilder saves a cookie named “et-editing-post-XXXX-fb”. XXXX being the post ID! πŸ™‚

    The downside is, multiple Divi Pagebuilder cookies with different post IDs can exist at the same time. Probably while editing multiple posts at once (didn’t fully understand the logic of deleting those).

    I therefore check at least for existence of my custom field as a countermeasure and in case I can’t get the post ID, I’ll echo out a placeholder message. Of course, it can happen that I mistakenly get post ID of a different post of the same post type (having the custom field I check for), but that’s a problem I can live with for now.

    So far, it seems to work pretty reliably in my case.

    Here’s the snippet from my shortcode…

    // While in pagebuilder, try to get the ID from a cookie of name "et-editing-post-POSTID-fb"
      if (is_et_pb_preview()) {
        foreach(array_keys($_COOKIE) as $cookie) {
          if (strpos($cookie, 'et-editing-post-') === 0) {
            $cookieID = (int)explode('-', $cookie)[3];
            if (get_field('my_custom_field_name', $cookieID)) {
              $postID = $cookieID;
              break;
            }
          }
        }
      } else {
        $postID = get_the_ID();
      }

    Any proposed improvements will of course be appreciated πŸ™‚