WP_Query vs get_posts

The difference between get_posts & WP_Query You can view get_posts() as a slimmed down WP_Query. In fact looking at the source: //… prepares query array $r $get_posts = new WP_Query; return $get_posts->query($r); get_posts() use WP_Query, but only returns an array of posts – nothing more. Furthermore it sets: $r[‘no_found_rows’] = true; Normally (by default with … Read more

Proper way to get page content

Just to clarify: You mixed two things here. qTranslate stores the different languages in the same post. If you call get_content(), $post->content or an other direct query, you will get the whole content with all different languages from the database. What qTranslates do, it creates a filter-hook which is attached to the_content hook. If somebody … Read more

How to get comments by post ID?

You can use get_comments. Function Reference/get comments $args = array(‘cat’ => ‘home’,’post_type’ => ‘post’)); $post_obj = new WP_Query($args); while($post_obj->have_posts() ) : $post_obj->the_post(); //display comments $comments = get_comments(array( ‘post_id’ => $post->ID, ‘number’ => ‘2’ )); foreach($comments as $comment) { //format comments } endwhile;

Count & Display Database Queries

You can paste this block of code in your currently active WordPress theme functions.php file: function wpse_footer_db_queries(){ echo ‘<!– ‘.get_num_queries().’ queries in ‘.timer_stop(0).’ seconds. –>’.PHP_EOL; } add_action(‘wp_footer’, ‘wpse_footer_db_queries’); The above block of code, will render an HTML comment in the footer of your theme (before </body> and </html>, containing the number of database queries and … 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.

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