- This topic has 5 replies, 2 voices, and was last updated 4 years, 8 months ago by Tom.
-
AuthorPosts
-
July 26, 2019 at 9:55 am #968022Vuong
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 😀July 26, 2019 at 5:05 pm #968209TomLead DeveloperLead DeveloperHi there,
That’s just the query – you would still need to build the HTML for the posts, which would include your title, excerpt, featured images etc.. It gets complex if you aren’t familiar with the templates.
Maybe a plugin like this might help?: https://wordpress.org/plugins/wp-show-posts/
If so, this topic should help: https://wpshowposts.com/support/topic/sort-by-custom-field-value/#post-7803
July 26, 2019 at 9:23 pm #968274VuongTks 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
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');
July 27, 2019 at 6:37 am #968509TomLead DeveloperLead DeveloperHi 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.
July 28, 2019 at 1:57 am #969031VuongTks..but not just 1 post,i want to show all posts,ordered by likes count descending
July 28, 2019 at 6:53 am #969167TomLead DeveloperLead DeveloperThat’s exactly what this should do: https://generatepress.com/forums/topic/page-template-2/#post-968209
It would list out the posts, and order them by the number specified in that custom post meta.
-
AuthorPosts
- You must be logged in to reply to this topic.