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

Query Posts or Get Posts by custom fields, possible?

To query posts by custom fields you can use the ‘meta_query’ parameter <?php $args = array( ‘post_type’ => ‘payment’, ‘meta_query’ => array( array( ‘key’ => ‘bookingref’, ‘value’ => ‘the_value_you_want’, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘customerref’, ‘value’ => ‘the_value_you_want’, ‘compare’ => ‘LIKE’ ) ); query_posts($args); while (have_posts()) : the_post(); ?> you can’t use get_post_meta … Read more

How to show related posts by category

The question has already been asked and the answer has been posted too, How to display related posts from same category? Add this code inside your single.php after a loop wherever you want to show related post, <?php $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID) ) ); if( $related … Read more

Display posts of the last 7 days

In addition to birgire’s solution, as of WordPress 3.7, you can use Date parameters. Your arguments would look like this to filter posts from the last 7 days: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // Using the date_query to filter posts from last week ‘date_query’ => … Read more

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