• I’m using Javascript in the browser, and fetch comment data using:

    
    jQuery.ajax({
        url: wp.ajaxurl,
        data: {
            action: 'wp_ajax',
            data: data
        }
    })
    

    And then I output the data. The problem is I only have the data, not the HTML that uLike adds to comments.

    I think what I want is the wp_ulike_comments function, but that expects to be run in the_loop, because it uses get_comment_ID(). Let’s say I fetch the comments from the database myself. How can I call wp_ulike_comments and pass in an array of comments to get HTML back out?

Viewing 1 replies (of 1 total)
  • Thread Starter tylercollier

    (@tylercollier)

    I almost have the answer. Rather than using the url from wp.ajaxurl, I should have been using the WP REST API, with a URL like https://mysite.dev/index.php/wp-json/wp/v2/comments?post=1.

    The problem I have now is that oddly doesn’t include a value for data-ulike-id. Note how it’s the empty string in the content JSON response:

    
    "content": {
      "rendered": "<p>Hi, this is a comment.<br />To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.<br />Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.</p><div id="wp-ulike-comment-" class="wpulike wpulike-default" ><div class="counter"><a data-ulike-id="" data-ulike-type="likeThisComment" data-ulike-status="3" class="wp_ulike_btn image"></a><span class="count-box">0</span></div></div>"
    }
    

    I can reproduce this. Do a fresh WordPress install of 4.8 with the uLike plugin and add a comment to the only existing post, then fetch the comments with the URL I mentioned above.

    • This reply was modified 7 years, 4 months ago by tylercollier.
Viewing 1 replies (of 1 total)
  • The topic ‘How to get uLike HTML/markup via admin-ajax.php?’ is closed to new replies.