How to Display Post View Count

Add this to single.php, and make sure you paste in inside the loop. <?php setPostViews(get_the_ID()); ?> Lastly, to display the number of views a post has, just add this where you want it to be displayed: <?php echo getPostViews(get_the_ID()); ?> . <?php // function to display number of posts. function getPostViews($postID){ $count_key = ‘post_views_count’; $count … Read more

Unable to display multiple post types in same query (WPML WP_Query)

I had this problem with querying on two custom post types, using WP_Query. I had no problem querying for one type or the other in the array, but not both at the same time. Did not work: $args = array( ‘post_type’ => array(‘custom_type_1′,’custom_type_2’), ‘posts_per_page’ => 4 ); Did work: $args = array( ‘post_type’ => array(‘custom_type_1’), … Read more

How to modify the query to exclude posts by slug?

You can get the post ID from the slug with the url_to_postid() function: $ID = url_to_postid(slug); then just exclude the ID from your query: query_posts(array(‘category_name’ => ‘Mycat’, ‘posts_per_page’ => -1, ‘post__not_in’ => $ID )); You can create an array of post IDs if you need to exclude multiple pages.

WordPress get posts by date without query_posts

Yes, simple add a filter before you call it and remove it after you do function filter_where_wpa89154($where=””) { //posts in the last 30 days $where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-30 days’)) . “‘”; return $where; } add_filter(‘posts_where’, ‘filter_where_wpa89154’); $args = array( ‘posts_per_page’ => 5, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ … Read more

Order post by year DESC and month ASC

To show a list by Year DESC and by month ASC: change your post type with custom_post. global $wpdb; $posts = $wpdb->posts; $sql = “SELECT DISTINCT(YEAR(`post_date`)) as years FROM $posts WHERE post_type=”custom_post” ORDER BY years DESC”; //Get all post year list by DESC $result = $wpdb->get_results($sql); foreach($result as $rs) { echo ‘<h2>’.$rs->years.'</h2>’; $args = array( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)