0

I am looking for a way to display or echo each post ID within my RSS feed. Basically when I access my RSS feed site, I get the following XML items: <title>, <link>, <comments>, <category>, <pubDate>, <guid isPermaLink>, <description>.

When I use this Google function in my code

var url = 'http://howtodeployit.com/category/daily-devotion/feed/';
        $.ajax({
        type: "GET",
        url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',

the returned Objects are title, link, author, publishedDate, contentSnippet...

What I also want returned is the Post ID but not sure how to get my WordPress to include that in the XML.

5
  • Anyone able to help or point me in the right direction Commented Oct 10, 2013 at 7:34
  • check out your guid tags in your feed, they include the post id's ( ...?p=123 )
    – birgire
    Commented Oct 10, 2013 at 8:53
  • Yes I know but Google Feed API does not pick it up. How do I get it to pick anything after ...?p= Commented Oct 10, 2013 at 11:09
  • One can easily add an extra custom tag to the feed, but it will not give you a valid feed structure, so I think using the guid instead might be a better option. You might try javascript regex to strip out the post ID from the guid.
    – birgire
    Commented Oct 10, 2013 at 11:32
  • Thanks birgire, your comment gave me an idea which I will post as my answer Commented Oct 10, 2013 at 13:51

1 Answer 1

1

How did I workaround this?

Step1: From my WordPress Permalink Settings, I selected Custom Structure and added /%post_id%/ This means my results will be in this format:

<myurl>/<postID>

Step2: To make it easier for me instead of writing a regex query I used a a Split command like this:

var postlink = entry.link;
var id = postlink.split(/\//)[3];

(///)[3] would simply split the URL by the number of slashes and take only that 3rd bit which is where my postID is.

I hope this comes in handy for others in my position.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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