WordPress.org

Forums

JSON API
Advanced Custom Fields (2 posts)

  1. dt99rrc
    Member
    Posted 11 months ago #

    Hi,

    I can see my Advanced custom field in my get posts request, but I can see how I am supposed to call it within the Javascript of my mobile app.

    I currently have -

    function listPosts(data) {
    var output = '<form class="ui-filterable"><input id="searchposts" data-type="search"></form>';

    output += '<ul data-role="listview" data-filter="true" data-input="#searchposts">';
    $.each(data.posts, function(key, val) {

    var tempDiv = document.createElement("tempDiv");
    tempDiv.innerHTML = val.excerpt;
    $("a", tempDiv).remove();
    var excerpt = tempDiv.innerHTML;

    output += '

  2. ';
    output += '';
    output += (val.thumbnail) ?
    '<img src="' + val.thumbnail + '" alt="' + val.title + '">':
    '<img src="images/copy-logo.png" alt="iDrum">';
    output += '<h3>' + val.title + "</h3>";
    output += '<p>' + excerpt + "</p>";
    output += '
    ';
    output += '
  3. ';
    }); //go through each post
    output += "";
    $('#postlist').html(output);
    } //listPosts

    What I want to do is to replace the link to the post to link to the web address in the ACF...

    Can anyone point me in the right direction? I can't seem to find any examples/tutorials online.

    Thanks!

    https://wordpress.org/plugins/json-api/

  4. dt99rrc
    Member
    Posted 11 months ago #

    Sorry it appeared to strip part of the code...

    function listPosts(data) {
      var output = '<form class="ui-filterable"><input id="searchposts" data-type="search"></form>';
    
      output += '<ul data-role="listview" data-filter="true" data-input="#searchposts">';
      $.each(data.posts, function(key, val) {
    
        var tempDiv = document.createElement("tempDiv");
        tempDiv.innerHTML = val.excerpt;
        $("a", tempDiv).remove();
        var excerpt = tempDiv.innerHTML;
    
        output += '<li>';
        output += '<a href="#blogpost" onclick = "showPost(' + val.id + ')">';
        output += (val.thumbnail) ?
          '<img src="' + val.thumbnail + '" alt="' + val.title + '">':
          '<img src="images/copy-logo.png" alt="iDrum">';
        output += '<h3>' + val.title + "</h3>";
        output += '<p>' + excerpt + "</p>";
        output += '</a>';
        output += '</li>';
      }); //go through each post
      output += "</ul>";
      $('#postlist').html(output);
    } //listPosts

Reply

You must log in to post.

About this Plugin

  • JSON API
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic