Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using JSON api plugin to pull data from wordpress into an app I am making. I need a unique identifier to make sure I don't have any duplicates WHILE also using the identifier as a way to sort from newest post to oldest post. As of right now I'm confused because I pull the 10 most recent posts. I then take the ID and I attempt to reach but I don't get the correct post. I get a different one. I'm starting to run out of ideas?

share|improve this question

2 Answers 2

If you look at the description for the different tables used by WordPress, the columns described as "auto_increment" will be unique.

I am not sure what you are doing though. The URL structure you are using is not one that I recognize. That is, the syntax I think you want is this:

rather than this:

?p= + a valid ID should always give you the post with the referenced ID number.

share|improve this answer
Hmm... I was able to get the post through api/get_post/?post_id=1774 – EGHDK Jan 18 '14 at 4:36
Your example in the question is Your example in the preceding comment looks to be passing data through an interface provided by the plugin. – s_ha_dum Jan 18 '14 at 15:20

Yes and No.

  1. Within a blog/site id's are unique. Unless they've been tampered with (by modifying the database's AUTO_INCREMENT, or reusing old id's, which would be a bad move).

  2. Within a Wordpress Multisite Network, id's are not unique. A blog post on one site can have the same id as a blog post on another site. Probably since each site has a separate database/table. (This just happened to me.)

  3. For third-party applications (like the app you are making) you shouldn't use id as a globally unique identifier for a blog post, since if you pull data from different wordpress sites/blogs, then two blogs posts, from two different blogs, might have the same id (for the same reason as stated in point 2, above.), and you might end up getting the wrong blog post when doing a query in your own database.

Instead: Use $post->GUID (GID means Global Unique Identifier, and is Wordpress' tool for this purpose), and never change it, even if the URL or the domain name of the blog changes (it's just an identifier, so it doesn't need to always match the url).

With the GUID, you won't be able to "use the identifier as a way to sort from newest post to oldest post.", but you can pass the client_db_published_at date and use that instead (it is more reliable and detailed anyways):

// When you already have the $post in question
"blog_post[client_db_published_at]" => = get_the_time('c', $post->ID); // c  = ISO 8601 = 2004-02-12T15:19:21+00:00  . T is just a whitespace separator here. Ref:
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.