1

I am creating a custom wordpress theme in that i am using following from github . Full Code

Now i am trying to list all the liked posts by the current login user but removing user likes not working here is my code.

<?php
/*
* Template Name: Likes
*/
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(); ?>

Removing button also added but the remove button not giving the perfect list. Thank for your time.

James Paul
  • 157
  • 1
  • 2
  • 14
  • maybe try using a different `compare` operator in your meta query parameters? instead of `LIKE` maybe try `=` or `EXISTS`...? – Mike C. Oct 24 '18 at 17:05
  • @MikeC. What i am trying to do is removing not showing alone. Showing was working fine. Need help with removing. – James Paul Oct 27 '18 at 06:57
  • So I understand... you are trying to show a list of the user's "liked" posts and then allow them to "unlike" some of the posts in that list? To do that it looks like you need to update both the user option data AND the post/comment meta data... see here: https://github.com/JonMasterson/WordPress-Post-Like-System/blob/acaa7e6d353c13904352bbb9424aad46bf56ab98/post-like.php#L99 – Mike C. Oct 31 '18 at 03:18

0 Answers0