Using OR conditions in meta_query for query_posts argument

Use ‘relation’ => ‘OR’ as in the Codex example below: $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( ‘relation’ => ‘OR’, /* <– here */ array( ‘key’ => ‘color’, ‘value’ => ‘blue’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘price’, ‘value’ => array( 20, 100 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) … Read more

WP_query parameters for date range

Copied from StackOverflow: WP_Query offers a date_query parameter, allowing you to set a range with before and after. https://developer.wordpress.org/reference/classes/wp_query/#date-parameters $args = array( ‘date_query’ => array( array( ‘after’ => ‘January 1st, 2015’, ‘before’ => ‘December 31st, 2015’, ‘inclusive’ => true, ), ), ); $query = new WP_Query( $args ); See the linked documentation for more details. … Read more

How to query post by user role?

I haven’t really messed around with custom post queries before, but here is my try at a solution: function get_posts_by_author_role($role) { global $wpdb; return $wpdb->get_results( “SELECT p.* FROM {$wpdb->posts} p, {$wpdb->usermeta} u” .” WHERE p.post_type=”post”” .” AND p.post_status=”publish”” .” AND u.user_id = p.`post_author`” .” AND u.meta_key = ‘wp_capabilities'” .” AND u.meta_value LIKE ‘%\”{$role}\”%'” ); } … Read more

How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling

First, for layout and CSS styling, I would recommend creating template files for the contexts you want to customize; i.e. create a category.php and a tag.php for the category and tag index archive pages, respectively. In either case, copy archive.php (or, if it doesn’t exist, copy index.php), and rename the copy as category.php. Then, modify … Read more

How to call a custom post with get_posts() instead of query_posts()?

Hi Elium2009: Using your code, I think this is what you were looking for? (note that WP_Query() is just the more direct version of get_posts()): <?php $posts = WP_Query(array( ‘taxonomy’ => ‘type-mario’ ‘term’ => ‘games’, ‘posts_per_page’ => 10 )); ?> <p>Mario games</p> <?php while ( $posts->have_posts() ) : $posts->the_post(); ?> <div id=”post-<?php the_ID(); ?>” <?php … Read more

Custom search filter causes menu and query_posts problems

Use is_main_query() to modify only the main query so menu will stay not affected. Try This: add_action( ‘pre_get_posts’, ‘fteh_pre_get_posts’ ); function fteh_pre_get_posts( $query ){ if( !is_admin() && $query->is_main_query() && isset( $query->query_vars[‘type’] ) ) $types = explode( ‘,’, $query->query_vars[‘type’] ); $query->set( ‘post_type’, $types ); return $query; }

Filtering custom taxonomies

This is not a tought quest, but you’d have to read carefully the Codex. Especially tax_query part of WP_Query. Your proposed query_posts call is wrong. This should look like this: query_posts( array( ‘post_type’ => ‘myportfoliotype’, ‘paged’ => $paged, ‘posts_per_page’ => 80, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, //or tag or custom taxonomy ‘field’ => … Read more

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