← Back to LJTools

LJ-XP ljID calculator

The Problem

When I wanted to mirror part of my LJ to a standalone WordPress blog, I came upon a curious problem.

The problem rised, because I wanted to link existing LiveJournal posts to WordPress ones, so I could edit WordPress post and get one in LJ changed too.

That is very easy when you have LJ Crossposter plugin in your WordPress blog, BUT! it works fine only with new posts that you create in WordPress. They are successfully crossposted, and updated in LJ as you edit them in WordPress. If you create post directly in LiveJournal and then create a copy in WordPress, LJ Crossposter doesn't provide a way to link those two posts together.

But I wanted that. After exploring WordPress database a bit I found that LJ-XP (LJ Crossposter) creates entries in 'posts_meta' database table. Entries have fields:

So, task seemed trivial:

  1. Import posts from LJ
  2. Create 'posts_meta' table entries with ljID = LJ itemid
  3. Have fun

...But where can we get that itemid? Obvious answer (every LJ post has numbers in it's URL, like http://%username%.livejournal.com/%numbers%.html - and when you export LJ entries with LJ's standard exporter the same numbers show up in XML as itemid - so that is probably a real item id) is wrong.

If you try to put that "public" itemid into your WordPress database's LJ-XP meta... you'll get error "Something went wrong – 302: Client error: Can’t edit post from requested journal" when you'll try to edit any of "linked" posts

So where is the real itemid?

Real itemid is "contained" in public itemid in a bit tricky way. The formula is:

public_itemid = itemid * 256 + anum

Quite easy, isn't it? Except where to get that anum. anum is some number assigned when you create a new post in LJ.

But in fact, you don't need it. Because it is always less than 256, we can avoid searching for it, and just use simple Math to find itemid.

$anum = $public_itemid - floor($public_itemid / 256) * 256;
$itemid = ($public_itemid - $anum) / 256;

That's it, now we have correct itemid! You can just put it into posts_meta WordPress database table and enjoy "crossposting" working.

Now, it's time for a little gift :-)

To ease that task for those of you who don't want to do programming yourself, I created this public service that quickly extracts itemid when you feed it with public itemid.



Best regards, drumrock

Enter LiveJournal post's public itemid (from URL, http://<username>.livejournal.com/<numbers here>.html):

public_itemid = 0
anum = 0
itemid = 0 (that's what you'll want to use as LJ-XP ljID value)

Related links: