Skip to content

Instantly share code, notes, and snippets.

@hofmannsven
Last active May 15, 2019 06:41
Show Gist options
  • Save hofmannsven/6421354 to your computer and use it in GitHub Desktop.
Save hofmannsven/6421354 to your computer and use it in GitHub Desktop.
How to create a Post Like System for WordPress.
@SHABU89
Copy link

SHABU89 commented Jul 23, 2018

How to Implement this code with a wordpress theme ?

@hofmannsven
Copy link
Author

You can find the full documentation here:
https://github.com/JonMasterson/WordPress-Post-Like-System

@SHABU89
Copy link

SHABU89 commented Oct 20, 2018

Is there any possibility to keep a remove button from in the list of liked posts (current-user-likes.php) In this is there any option to keep remove button for each liked post to remove individually.

@SHABU89
Copy link

SHABU89 commented Oct 21, 2018

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 = ' &middot; ';
			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(); ?>

@SHABU89
Copy link

SHABU89 commented Nov 15, 2018

Getting following error while integrating.

Fatal error: Uncaught Error: Call to undefined function AlreadyLiked() in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment