1

Channel Ratings: 4.0.4, EE: 2.7.3

I am using the channel ratings "Like" function, so the logged in users can "Like" certain products. I want to be able to display who has liked an entry. I am using this bit of code to display the "like_author_id" which happens to be the same as the "member_id"

{exp:query 
   sql="SELECT * 
   FROM exp_channel_ratings_likes
   WHERE entry_id = '{entry_id}'
   AND liked > '0'
"}
   {if like_author_id != "0"}
      <a href="{path='/likes/{like_author_id}'}">{like_author_id}</a>,
   {/if}
{/exp:query}

I am wondering how I can display the screen_name of the author who liked the entry.

ps. I tried to tag channel-ratings, but I couldn't with under 150 reputation.

1 Answer 1

2

I'm not entirely familiar with Channel Ratings, but you should be able to do what you're looking for with the query.

Try this:

{exp:query 
   sql="SELECT exp_channel_ratings.*, exp_members.screen_name as like_screen_name 
   FROM exp_channel_ratings_likes, exp_members
   WHERE entry_id = '{entry_id}' and exp_channel_ratings.like_author_id = exp_members.member_id
   AND liked > '0'"}
       {if like_author_id != "0"}
          <a href="{path='/likes/{like_author_id}'}">{like_screen_name}</a>,
       {/if}
{/exp:query}

Note: You may want to change that exp_channel_ratings.* to use the specific fields you want to query, reducing the number of fields pulled back in your query. Could help with performance.

3
  • Awesome thanks Jeremy, I've been trying a few things along this line, but it still pulls in the screen_name associated with the entry, and not the "like". I'll try playing around with this code and let you know if it works!
    – Funkefied
    Feb 7, 2014 at 19:55
  • I've just updated the query to alias the screen_name field to {like_screen_name}. It may have been conflicting with the outer channel entries tag. Feb 7, 2014 at 20:09
  • "as like_screen_name" did it! You're my hero Jeremy
    – Funkefied
    Feb 7, 2014 at 20:17

Your Answer

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

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