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

Using meta_query, how can i filter by a custom field and order by another one?

This seems to be a bug in WordPress. WordPress actually modifies the meta_query if you specify orderby and meta_key as query vars. Normally this modification adds the new meta_key as the first array in meta_query array and hence the orderby is applied to the first meta key specified in meta_query. But when you modify orderby, … Read more

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