Hide other users’ posts in admin panel

Here is what I use: // Show only posts and media related to logged in author add_action(‘pre_get_posts’, ‘query_set_only_author’ ); function query_set_only_author( $wp_query ) { global $current_user; if( is_admin() && !current_user_can(‘edit_others_posts’) ) { $wp_query->set( ‘author’, $current_user->ID ); add_filter(‘views_edit-post’, ‘fix_post_counts’); add_filter(‘views_upload’, ‘fix_media_counts’); } } // Fix post counts function fix_post_counts($views) { global $current_user, $wp_query; unset($views[‘mine’]); $types = … Read more

How to query for most viewed posts and show top 5

View this section of the Codex to learn how to create a custom query: http://codex.wordpress.org/Class_Reference/WP_Query Your query will be something like: $query = new WP_Query( array( ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘posts_per_page’ => 5 ) ); By default, the ordering will be highest to lowest, thus giving you the “top” 5.

How to show all posts of the category in wordpress?

<?php $args = array( ‘category’ => 7, ‘post_type’ => ‘post’ ); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?> <h2><a href=”https://wordpress.stackexchange.com/questions/17496/<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endforeach; ?> just change the category id (number 7) and change the post_type that was in the plugin to learn more about … Read more

how to query posts by category and tag?

Edit: See below for proper way to query category and tag intersections. global $wp_query; $args = array( ‘category__and’ => ‘category’, //must use category id for this field ‘tag__in’ => ‘post_tag’, //must use tag id for this field ‘posts_per_page’ => -1); //get all posts $posts = get_posts($args); foreach ($posts as $post) : //do stuff endforeach;

How to get posts published between a date and today?

UPDATE December 23 2014 There is a better method using date_query property of WP_Query class: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-image’ ) ) ), ‘cat’ => ‘-173’, ‘post_status’ => ‘publish’, ‘date_query’ => array( ‘column’ => ‘post_date’, ‘after’ => ‘- 30 days’ … Read more

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