Viewing 1 replies (of 1 total)
  • I’d add a data-id attribute to the anchor element that I’m trying to fetch. In order to keep things SEO friendly, make sure you have a fallback template for the full URL.
    <a href="mysite.com/portfolio/my-item" data-id="1432">View portfolio entry</a>
    Then, in jQuery, you can fetch the id via:

    jQuery(function($) {
      $("[data-id]").on('click', function  (){
        var id = $(this).data('id');
        //Use id for JSON API now :-)
       })
    })

Viewing 1 replies (of 1 total)
  • The topic ‘How to get post id by id on click’ is closed to new replies.