How to make Fake Views on WordPress

Use something like this : (add it in your function.php) and load your site once. after it finish, deactivate the function. (don’t forget to declare your $postID) function my_update_posts() { $count_key = ‘post_views_count’; $args = array( ‘post_type’ => ‘post’, ‘numberposts’ => -1 ); $myposts = get_posts($args); foreach ($myposts as $mypost){ $mypost->post_title = $mypost->post_title.”; $count = … Read more

Post rank by views

Is there any specific reason you are using $wpdb? You can do the same with WP_Query which is always recommended. So if your meta key for counting post views is views then you can run this WP_Query to return top viewed posts. You can also limit results by posts_per_page. <?php $args = array( ‘post_type’ => … Read more

Updating post_views_count on publish [duplicate]

So this is the code I earlier posted. // Create custom field on post publish function wpse_custom_field_on_publish( $new, $old, $post ) { if ( $new == ‘publish’ && $old != ‘publish’ && !get_post_meta( $post->ID, ‘post_views_count’, true ) ) { add_post_meta( $post->ID, ‘post_views’, rand(829, 1013), true ); } } add_action( ‘transition_post_status’, ‘wpse_custom_field_on_publish’, 10, 3 ); Let … Read more

Display (custom) post number of views

This is a repurposed post from another question which the OP did not find useful, so I’m reposting it here and hopefully will be useful here Please modify the code as needed. Here is a post I have recently done on stackoverflow. It is a modified version of the code you are using. I had … Read more

Get taxonomy image for Toolset custom taxonomy through Toolset Views Shortcode

The following code is partialy taken from the plugin Taxonomy Images and it’s working: function get_taxonomy_image( $atts ) { $atts = shortcode_atts( array( ‘image_size’ => ‘thumbnail’, ‘id’ => ”, ), $atts ); if( ! empty( $atts[‘id’] ) ) { $term = get_term( $atts[‘id’] ); $related_id = 0; if ( isset( $term->term_taxonomy_id ) ) { $related_id … Read more

Integrating CSS Into a WP Function Call [closed]

Apart from the fact, that the conditional is based on a WordPress option, this is pure PHP, but anyhoo: <?php $show_views = get_option( ‘to_post_views’ ); if ( ‘Yes’ === $show_views ) { echo ‘<div class=”postviews”>’ . getPostViews( get_the_ID() ) . ‘</div>’; } ?>

Changing comment_count to views

Yes, you have to calculate page views. Do not use plugin as it needs a small piece of code. Below code will increase pageviews and will store in post meta. Use this code in single.php or loop-common. if( is_single() ) { /* Increase post view count by 1 */ $post_view_count = get_post_meta($post_id, ‘view_count’, true); if( … Read more