WordPress query_posts with multiple tax_query

You could build an intermediary array for the tax_query parameter: $tax_query = array(); $taxonomies = array( ‘product_cat’, ‘sub_category’, ); foreach ( $taxonomies as $taxonomy ) { if ( ! empty( $_POST[ $taxonomy ] ) ) { $tax_query[] = array( ‘taxonomy’ => $taxonomy, ‘terms’ => $_POST[ $taxonomy ], ); } } query_posts( array( // … ‘tax_query’ … Read more

Developing a “fallback” for empty wp_query results based on post dates

PHP strtotime() takes some weird string values that we can use in combination with the WP_Query date_query ‘before’ keyword. For example, we can get X posts before 1 year before tomorrow: $tomorrow_a_year_ago = wp_date( ‘Y-m-d’, strtotime( ‘-1 year +1 day’ ) ); $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ‘post_status’ => ‘publish’, ‘orderby’ … Read more

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