jonmasterson / wordpress-post-like-system Goto Github PK
View Code? Open in Web Editor NEWA simple and efficient post like system for WordPress.
A simple and efficient post like system for WordPress.
Hello, i receive this error in webmaster for every post when u give like
wp-admin/admin-ajax.php?action=process_simple_like&nonce=ae6e6de73a&post_id=410&disabled=true&is_comment=0
What is the problem?Thanks
Pls remove 'YourThemeTextDomain' with this following code block -
$my_theme = wp_get_theme();
echo $my_theme->get( 'TextDomain' );
Ref: https://codex.wordpress.org/Function_Reference/wp_get_theme
Hi
I really need a like system on my blog and i tried this one.
But the script is not added in the theme and therefor the link won't work. I did exactly as you wrote in the readme file and still...
After that i added the script, just for test, in header file, and after that before /body and there wasn't any change. When i click on the link, it'll move the scroll to top of the page.
What do you think is the problem?
hello
i want visitor after click liked post can't click dislike.
thanks
Keep getting an error when clicking the Like button. It's probably something really obvious but I'm completely stumped:
Uncaught ReferenceError: ajax_var is not defined
Hi Jon and team. Great Like System - Is there any way to order posts by most liked?
Thanks in advance.
Neil
Hi @JonMasterson
thank you for developing this.
Is there a way for you to make plugin available on wpackaginst as composer package?
thanks
Is there a way I can manipulate the number of likes the heart displays or starts off?
For example each post with the heart/like starts at 0 is there a way we can adjust the like number to start at like 25 or 213?
Also is there a way the like/heart can have the letter 'k' after it reaches 1000 likes
For example 2,452 will translate to 2,45k or 2.4k
Awesome plugin! Lightweight & simple to integrate.
Hey there--
Wondering if it might be possible through some arithmetic to calculate the total number of likes an author's posts (in total) have received to display it on their author profile page?
The use case would be a multi-author site to gamify authorship and have bragging rights / top authors (not necessarily to display as a list, but if an author wanted to compare their likes to another's).
I'm using your Code to let Users like custom post types and it's working great! The only thing is, that liked posts, that don't have a title, are not appearing in the Users Profile view. Only Posts with a title are shown. But Wordpress assigns a unique ID to the post, so the title isn't really needed.
But if i like a social media post with no title, it's not appearing in the user profile.
How to achieve this?
Is this project still maintained?
Hi there,
I have your plugin running on my website... it was all ok (I really liked it) but now when I access google webmaster tools It shows many software errors (google official link for tis error https://support.google.com/webmasters/answer/2409443?ctx=MCE&ctx=S4)... Now I have 491 software errors .... A usual link error seems like:
http://www.website.com/wp-admin/admin-ajax.php?action=process_simple_like&nonce=e9509175b0&post_id=12121&disabled=true&is_comment=0
What this error mean? And how I can solve it?
Thanks
Hi,
I have a like icon at two places in my website ,
What i need , is that if i like form one icon and it show count , the other can also update automatically ,?
Is this plugin provide such functionality ...?
Please reply asap
Hello,
You have a very nice code, but I think there is one line that might be a Security Issue -
$is_comment = isset( $_REQUEST['is_comment'] ) ? $_REQUEST['is_comment'] : 0;
Might be used for Injection attack etc.
I would rather use -
$is_comment = isset( $_REQUEST['is_comment'] ) ? 1 : 0;
Just a suggestion.
There no issue here (yet!). I only logged in to say a big thank you for putting this out. Looking at all the help you have provided folks with different customizations, I want to say you are one of those rare selfless people who can go out of their way to help a person.
Thank you and stay like this!
I'm just wondering how hard would it be to modify this to work without wordpress. Non-programmer here, but I've seen PHP code around... I guess I'm just wondering if there is a point for me even starting it (like if it's too complex for php noop to comprehend), I mean I'm up for the challenge, I just don't know how tall of a mountain this would be for me. And if I should try and find something else already available?
Any advice would be appreciated very much.
Cheeers
Removing liked posts from page template not working. But added same code how it was for posts page.
<?php
/*
* Template Name: Liked Posts
*/
get_header();
$current_user = get_current_user_id();
?>
<table class="form-table">
<tr>
<th><label for="user_likes"><?php _e( 'You Like:', 'YourThemeTextDomain' ); ?></label></th>
<td>
<?php
$types = get_post_types( array( 'public' => true ) );
$args = array(
'numberposts' => -1,
'post_type' => $types,
'meta_query' => array (
array (
'key' => '_user_liked',
'value' => $current_user,
'compare' => 'LIKE'
)
) );
$sep = '';
$like_query = new WP_Query( $args );
if ( $like_query->have_posts() ) : ?>
<p>
<?php
while ( $like_query->have_posts() ) : $like_query->the_post();
echo $sep;
$post_id = get_the_ID();
$nonce = wp_create_nonce( 'simple-likes-nonce' );
$is_comment = '0';
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?></a>
<?php echo $post_id; ?>
<a href="<?php echo admin_url( 'admin-ajax.php?action=process_simple_like' . '&post_id=' . $post_id . '&nonce=' . $nonce . '&is_comment=' . $is_comment . '&disabled=true') ?>">Remove</a>
<?php echo do_shortcode('[jmliker]'); ?>
<?php
$sep = ' · ';
endwhile;
?>
</p>
<?php else : ?>
<p><?php _e( 'You do not like anything yet.', 'YourThemeTextDomain' ); ?></p>
<?php
endif;
wp_reset_postdata();
?>
</td>
</tr>
</table>
<?php get_footer(); ?>
Hello JonMasterson, I'm using your plugin but I had to make a change in the header thus leaving.
Plugin Name: WordPress Post Like System
Plugin URI: http://jonmasterson.com/
Description: A simple and efficient post like system for WordPress.
Version: 4.0
Author: Jon Masterson
Author URI: http://boliquan.com/
Text Domain: WP-POST-LIKE
Domain Path: /lang
after Adding this code in function.php , whenver i am trying to submit a contact form, it shows me error--Unexpected token < in JSON at position 1..
The Like functionality is working fine but it is affecting my contact form, pls help me with this..
I'm using ACF repeater to display photos gallery.
obviously it doesn't work and change all photos when clicking on 1 photo.
is there any chance I can change something in the code and make it work with ACF repeater?
hello,
thanking you for providing with such a great code. between, would like to know why the likes dont stay for all my posts. for few, it does and for few, it doesnt. i am not able to understand the reason. any suggestion?
regards
I've noticed that the like counter (as well as the shape fill) don't work properly (or update right away) when an anonymous user does the liking. I believe this is a cache-ing issue during the calls to update_post_meta() and update_comment_meta().
Thank you for your work its so usefull. i am changed output sort $count . $loader . $icon but when i click its turning default i want to pull text left side but i couldnt :(
is it possible to just display the likes a post got.....something like a non-clickable version....not sure what to call it....may be it can be called a muted version
for example
I will place the likes in the single post for users to click on it and register/unregister a like..... but on the home page(for instance a static home page to display latest/featured posts ) I just want to display the number of likes a post got, the user can not click the like icon to register a like, just display the likes.
Hi,
I have a suggestion to modify the code.
Currently the code is written in a way that it only supports POST/PAGE and COMMENTS.
Specially, checking of COMMENT is done by $is_comment flag-variable.
Here is the problem, we want to use the LIKE system may be also for MarketPlace posts, bbPress and BuddyPress activities etc. At current stat of the coding its hard to modify.
I would like to suggest you to change the code so that all the LIKE functions will take two parameters - ID and type. type { 'P' for Page/Post, 'C' for Comments, 'M' for MarketPlace, 'B' for bbPress etc. }
If type parameter is other than 'P' or 'C', it will just call a custom function say - get_simple_likes_button_B() which will be custom written.
This will help us to use this code and implement it for different plugins.
How do I show only the count? Without the icon?
Found an issue when run this system with BuddyPress plugin.
If a user (role: subscriber) is login and click to like/dislike a CPT which author is himself, the $response variable not return the parameters (status, icon, etc.), but the complete code of member page.
This remove the button icon and text.
Hi, do I show the top rated by category id number?
Example I want to show you the 5 most popular content by 1 category id.
content title and picture will be enough.
Hey there
Great code! Just a question: How can we use this without enqueue the script in the functions.php?
function sl_enqueue_scripts() {
wp_enqueue_script( 'simple-likes-public-js', get_template_directory_uri() . '/js/simple-likes-public.js', array( 'jquery' ), '0.5', false );
wp_localize_script( 'simple-likes-public-js', 'simpleLikes', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'like' => __( 'Like', $textdomain ),
'unlike' => __( 'Unlike', $textdomain )
) );
}
I'm using Sage which bundles all the scripts so i don't want separate scripts in my functions.php, how can i achieve this? Or would it be possible to just place all of this in a plugin?
Now want to display all users list who liked the post in single page under any specific div. Other things in this wordpress post like system have dislike system. But i want to remove dislike system. When a user liked a post. Then the button disable. Because The user cannot do like again or anymore on that post.
When I query posts to show the most-liked posts for all time (function 12) I see that even after I unlike a post, itβs still listed as most-liked. This is a bug that someone else commented on in the original post about this. Please assist.
when i click on the icon ajax does not load and like don't added here is the site link
First off, thanks for the work on this script.
It works fine for me on localhost, but on wpEngine - whenever I click the like link - it disappears. I refresh the page, and it is as if nothing was clicked.
Could this be an issue with the wpEngine's cache layering?
Thanks!
I'm trying to change the icon position so it's to the right of the "Like" text. I modified the $output
so it's wrapped in a <div>
instead of a <span>
and I'm using my own custom icons.
I also changed the $output
so it's $count . $icon
, which displays correctly by default, but when clicked it moves the icon back to the left when it shows the count.
Is there something else that needs to be modified to keep the icon on the right?
I don't see the "Unlike" text. Is that setup only for comments?
I'd also like to show the likes count by default, even if someone hasn't liked it yet.
Is it possible to show it as: Like Text -> Icon -> Count, and if it has been liked: Unlike Text -> Unlike Icon -> Count ?
Alternatively (and probably best) would be to just show the like count above this button, such as "xxx people like this" and then below I'd have the like button with Like Text -> Icon and when clicked it would show Unlike Text -> Unlike Icon without the loading text popping up. Either way, need the icon on the right ;)
any info is appreciated, and thanks for the cool tool π
p.s. I'm not a programmer so maybe I'm just missing the obvious stuff in the code after 18 hours of work.
I see this error when I install this code in my theme at google chrome console
JQMIGRATE: Migrate is installed, version 1.4.0 jquery-migrate.min.js?ver=1.4.0:2
how can I fix this issue ?
hi, very nice addon I love it and I am using this code to display users who liked post ,
$userlikes = get_post_meta( get_the_ID() , '_user_liked', true );
if ( ! empty( $userlikes ) ) {
$user_query = new WP_User_Query( array( 'include' => $userlikes, 'number' => 4, 'order' => DESC, ) );
}
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
?>
<span><?php echo $user->user_login; ?></span>
<?php
}
}
but need to refresh page to see new users who liked, I need little help to use ajax display this result, without refresh page,
Hi,
I love this plugin. It's very easy to setup and minimal for what it does.
But I am in need to create 2 buttons for like and dislike. More like vote up and vote down button.
Can it be done with this plugin? Looking for a light weighted solution for this.
Please suggest.
I've tried to manipulate a couple of the functions to get this solution, but I'm not having any luck.
Basically my client is asking that I have a display of all "likes" from the total of all the posts of this custom post type. Its kind of a "here's how much activity this site is getting" kind of a statistic.
Is this possible?
Hi Jon & Other Interested Parties (this means you),
I'm evaluating your awesome like system on a clean WordPress install using the stock Twenty Fifteen WP theme:
https://just-post-likes-micahbolen.c9.io/
I made 0 modifications to your code and 0 modifications to the stock WordPress code and I hope I followed your simple installation instructions adequately (pretty sure of this as I triple-checked).
I am seeing intermittent inconsistencies with the like count and intermittent unexpected behavior when the like button is pressed. I want to say that the problems are more frequent when testing as an anonymous user, but I'm not certain if that's the only time I see the problems.
I'm not getting any JS or PHP errors. Again, this is a clean WP install. No other plugins and no obvious library conflicts or anything of that nature.
I'm reaching out to you (Jon in particular) primarily because I could not reproduce the problems I was seeing on my sandbox on your demo page: http://jonmasterson.com/post-like-demo/
It seems that your demo page runs just fine and I assume the related code on your demo page is pretty much identical to what is available in this repository. However, I did notice that your demo page seems to take a little longer to process "likes" than my sandbox. Ever so slightly longer. Perhaps, it is because your demo page has lots of likes and, therefore, it takes longer to count them all. That is what I assume. So, that brings me back to my sandbox of a clean WP install.
Any assistance or recommendations from anyone watching this repo would receive much kudos and praise for anything that is in the least bit helpful.
Kind Regards,
Micah
Only with admin user it works perfect. Plz, help me to fix it. Is it only my problem? http://cpf.rusdigi.name/ here the like icon
http://cpf.rusdigi.name/login
test / test
Hi guys,
I was wondering if you know any way to sort posts by the number of likes they have?
I know I can do that using 'orderby' => 'meta_value_num'
but then it won't include the results that don't have the post meta value in the database.
Thanks!
Hey Jon - great stuff here, thanks for sharing. Quick but stupid question: how do I update the FA icon from a heart to a thumbs up (or any other FA icon)? Thanks again!
I want to display usernames who liked the post in single page . is it possible?
When i'm logged in i can like the post and when i'm log out i can also like the post. So a same user can like two times the same post.
Is it normal ?
Hello sir, It would be nice if I can hit the like button without reloading/refreshing the full page. Can anyone please help me to turn off the refresh option?
It is happening when I am trying to use this in my single.php
Wonderful code, thank you.
Tho I'd like to retrieve all users that is liking the current item.
Any pointers? I would be delighted.
Hi Jon,
WP function update_post_meta( $post_id, "_user_liked", $post_users ) will never be called, because $post_users as result of the function post_user_likes( $user_id, $post_id, $is_comment ) is always empty. So the meta key "_user_liked" will never be added in WP.
That's why you won't be able to check, if the user has already liked or not.
Am I right or do I miss something?
Thanks
I am displaying the post items and wanted to add the like button there also not only in single page and when putting it didnt work properly?Is it possible to fix?Thanks!
Hello! I'm using your code for years now on this site and it was working like a charm! But now, all of the sudden, it stopped working and i can only imagine that it is a compatibility issue with the latest Wordpress version.
If you visit the site above, it will probably show you some posts with the flag "liked" in red, even though you probably never liked a post on that site. Because of this, people are toggling each others likes instead of adding up. The communication with the backend is still working but it is not possible anymore to have more than 1 like on 1 post.
Those with more are older or i've set that manually as a test.
Any help would be very appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.