How to build a WP_Query using mulitple tags and using AND or OR operator between them

Give something like this a try: (it came from the same page you linked to, just scroll down a bit more). $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, // searches for posts meeting both conditions array( ‘taxonomy’ => ‘midgets’, ‘field’ => ‘slug’, ‘terms’ => array( ‘tagA,TagB’ ), // searches for … Read more

How to filter query to display posts from parent category only?

I was finally able to get this to work using the filter provided by the plugin. The query uses [cat] to get the category which doesn’t support the include_children parameter. Therefore, I had to define the tax_query argument before unsetting [cat]. Here’s the function: add_filter( ‘miniloops_query’ , ‘miniloops_child_posts_filter’ ); function miniloops_child_posts_filter( $query ) { $query[‘tax_query’] … Read more

popular post weekly and monthly

These $args is what you need and you may also use that in query_posts(); $args = array( ‘post_type’ => array( ‘post’ ), ‘post_status’ => ‘publish’, ‘posts_per_page’ => 9, ‘cat’ => $link1, // try better variable name ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘date_query’ => array( array( ‘after’ => ‘1 months ago’, ), … Read more

Query/list all terms and their custom post count

If the taxonomies in question are used ONLY in the post_type in question, then the following simple function will do what you need: function count_term_use ($post_type) { $args = array ( ‘taxonomy’ => get_object_taxonomies ($post_type, ‘names’), ) ; foreach (get_terms ($args) as $term) { echo “$term->name – $term->count\n” ; } return ; } However, if … Read more

Five posts from a category in footer

First: don’t use query_posts. Second: use $wp_query instead: $args = array ( ‘category_name’ => ‘entertainment’, ‘posts_per_page’=> 5 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } echo ‘</ul>’; /* Restore original Post Data */ wp_reset_postdata(); } else … Read more

What’s a better alternative to this code?

Thanks to those who’ve suggested fixes. I couldn’t get my normal pagination working with either, but did find an alternate solution which seems to work and which I’ll include here as possible help to others (because I’ve seen various requests for similar). <?php $wp_query = new WP_Query(); $wp_query->query(‘post_type=host&sort_by=title&order=ASC&showposts=1&paged=’.$paged ); get_template_part( ‘page-templates/partial/paginate’ ); while ($wp_query->have_posts()) : … Read more

Store sticky post’s ids in a transient

You can try: add_action(‘update_option_sticky_posts’, function( $old_value, $value ) { $featured_args = array( ‘post__in’ => $value, ‘post_status’ => ‘publish’, ‘no_found_rows’ => true ); // The Featured Posts query. $featured = new WP_Query( $featured_args ); // Proceed only if published posts with thumbnails exist if ( $featured->have_posts() ) { while ( $featured->have_posts() ) { $featured->the_post(); if ( … Read more

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