Site logo

Archived topic

Page template ?

5 replies · Started by Vuong on July 26, 2019

Viewing posts 1–6 of 6

Hello..could you pls help me.
Im using WP U Like to make a like system for wordpress..trouble is,i dont know how to show most liked post..i checked faq then they said :
use this code
"<?php
$the_query = new WP_Query(array(
‘post_status’ =>’published’,
‘post_type’ =>’post’,
‘orderby’ => ‘meta_value_num’,
‘meta_key’ => ‘_liked’,
‘paged’ => (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1
));
?>"
i dont know how to use,somebody said i need page template..but i dont see any page template in my wordpress.
so could you pls help me..tks :D

Tks for reply..but it doesn work..but nvm..could you help me another problem ?
here my code to get post view and show post view..
i put it in function file,its show ok,but i cant make it to show most viewed post,even using wp-show-posts plugin..so any chance to make it possible ?
Here my screenshots on wp-show-posts config and my database
https://i.imgur.com/XhILU7x.jpg
https://i.imgur.com/Nx3nciD.jpg
Sorry for disturb too much.

function setPostViews($postID) { 
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}
function post_like_table_create() {

global $wpdb;
$table_name = $wpdb->prefix. "post_like_table";
global $charset_collate;
$charset_collate = $wpdb->get_charset_collate();
global $db_version;

if( $wpdb->get_var("SHOW TABLES LIKE '" . $table_name . "'") != $table_name)
{ $create_sql = "CREATE TABLE " . $table_name . " (
id INT(11) NOT NULL auto_increment,
postid INT(11) NOT NULL ,

clientip VARCHAR(40) NOT NULL ,

PRIMARY KEY (id))$charset_collate;";
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
dbDelta( $create_sql );
}

//register the new table with the wpdb object
if (!isset($wpdb->post_like_table))
{
$wpdb->post_like_table = $table_name;
//add the shortcut so you can use $wpdb->stats
$wpdb->tables[] = str_replace($wpdb->prefix, '', $table_name);
}

}
add_action( 'init', 'post_like_table_create');

Hi there,

Just to confirm, you want to show the one post with the most views? I'm not really sure how you'd do that, unfortunately. I'll think about it today - will hopefully come up with a solution.

If I can't come up with something, you may need to use a service like codeable.io to have it coded.

Tks..but not just 1 post,i want to show all posts,ordered by likes count descending

This archived topic is closed to new replies.