$query conflicting with other queries in the same page

function pre_get_posts( $query ){ if(isset($query->getpostlist) && $query->getpostlist) { add_filter( ‘posts_fields’, ‘postsetupFields’, 20); } else { remove_filter( ‘posts_fields’, ‘postsetupFields’, 20); } return $query; } function postsetupFields( $fields ){ global $wpdb; $fields = “{$wpdb->posts}.ID”; return $fields; } add_action( ‘pre_get_posts’, ‘postsetupFields’);

Display posts where date field matches current month?

You can use the meta_query parameter to display all events for the current month like this: $start_date = date( ‘ym01’ ); $end_date = date( ‘ymt’ ); $meta_query = array( ‘key’ => ‘event_date’, ‘value’ => array( $start_date, $end_date ), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ); $args = array( ‘post_type’ => ‘hh_event’, ‘posts_per_page’ => -1, ‘orderby’ … Read more

Multiple loop for “featured” items returns wrong posts

Your second loop is fine because it works – although it is probably more efficient to do it this way: $args = array( ‘post_type’ => ‘onourradar’, ‘posts_per_page’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘offset’ => ‘2’); $my_query = new WP_Query($args); while ($my_query->have_posts()) : $my_query->the_post(); The difference is that a do_not_duplicate query is just … Read more

WP_Query based on a custom field result

Here’s the corrected code, thanks @Milo! <ul> <?php $recentPosts = new WP_Query(); $recentPosts->query(‘showposts=6&cat=1&meta_key=ticker&meta_value=yes’); ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li> <?php if ( has_post_thumbnail() ) {?> <div class=”post-thumb-140″> <a href=”https://wordpress.stackexchange.com/questions/78477/<?php the_permalink() ?>”><?php the_post_thumbnail( ‘post-thumb-140’ ); ?></a> </div> <!–post-thumb–> <?php } ?> <a href=”https://wordpress.stackexchange.com/questions/78477/<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a> </li> <?php endwhile; ?> </ul>

Is it possible to use WP Query to orderby custom meta value and custom taxonomy?

I have the similar query in my blog. This my args array : $args= array( ‘post_type’ => ‘box’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘position’, ‘order’ => ‘DESC’, ‘orderby’ => ‘meta_value_num’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomyname’, ‘field’ => ‘slug’, ‘terms’ => ‘yourterm’ ) ) ); Hope it will help you

loop and in admin header problem

Move the query part to a separate function that returns the data you need: function rs_get_scripts_data(){ $array = array(); // query + add stuff to array return $array; } and use it with wp_localize_script like: $array = rs_get_scripts_data(); $myscript_vars = array( ‘array’ => $array ); wp_localize_script( ‘myscript’, ‘myscript’, $myscript_vars );

Using Query In Post Type Archives

Change it from: ‘category_name’ => celebrity, ‘orderby’ => 1, into ‘category_name’ => ‘celebrity’, ‘orderby’ => ‘date’, // or something else Otherwise celebrity will be treated as a constant name, not a string. Also, you can’t order by 1, you have to use one of the ordering parameters.

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