WP_Query Ignoring `post_type` parameter

Try this <?php $args = array( ‘post_type’=>’weather_today’, ‘orderby’=>’ID’, ‘order’=>’ASC’, ‘posts_per_page’=>1 ); $query = new WP_Query( $args ); while ( $query->have_posts() ) : $query->the_post(); //loop endwhile; wp_reset_postdata(); ?>

WP_Query no posts with tax_query

Your query can be simplified to this: $products = new WP_Query([ ‘post_type’ => ‘post’, ‘show_product_on_only_premium’ => ‘yes’, ]); echo var_dump($products->posts); The culprit was likely the ‘operator’=>’AND’, the default value is IN, so changing your original query to use IN instead of AND would also work, as would removing the operator parameter as the default is … Read more

How to get posts on a specific date – WP Query

<?php // primarily get $year, $month and $day $args = array( ‘date_query’ => array( ‘year’ => $year, ‘month’ => $month, ‘day’ => $day, ) ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { // do whatever here } }

Get ONLY the count from wp_query without fetching posts

The found_posts property of the WP_Query class is what you’re looking for, which is the amount of found posts for the current query. However, you got a 0 because you set no_found_rows (in the $query array) to true, which means the amount there will not be calculated. I.e. WordPress will not append SQL_CALC_FOUND_ROWS to the … Read more

Pass array of taxonomy terms to wp_query

The problem is ambiguity, you can’t just put in ‘relation’ => ‘OR’ in the main parameter list, because how would WP_Query know if it’s for the tax_query and not the meta_query? For how it’s supposed to work, and where the relation parameter goes we need to refer to the official docs for WP_Query which gives … Read more

$wpdb insert is not work

First insert the global. global $wpdb; Then You have to check your quotes properly. $sql = $wpdb->prepare( “INSERT INTO `$table_name` (`name`,`email`,`phone`,`message`,`rq`,`url`) values ($name, $email, $phone, $address, $msg, 1, $url)”); $wpdb->query($sql); OR $wpdb->insert(‘$table_name’, array( ‘name’ => $name, ’email’ => $email, ‘phone’ => $phone, // … and so on ));

Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX

Because of this line: $paged = get_query_var( “paged” ) ? get_query_var( “paged” ) : 1; This is inside a function that is used on both an AJAX handler, and on a page request. get_query_var pulls the parameters from the main query ( aka the primary WP_Query that powers functions such as the_post, have_posts() etc ). … Read more

Mysql query LIKE not working

Prepare your Queries! global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT %s blog_id, last_updated FROM %s WHERE public=”1″ AND archived = ‘0’ AND mature=”0” AND spam = ‘0’ AND deleted =’0′ AND UPPER(blog_name) LIKE ‘%s’ %s %s “, ARRAY_A ), $extra, $wpdb->blogs, $wpdb->esc_like( ‘A%’ ), $order, $limit ); Never ever send data without prepare! Also: There’re some functions … Read more