how to get Nearby zipcode

Most likely your values $latitude and/or $longitude are not what you expect them to be. So radians($latitdue) becomes radians() or radians(”). For getting a single row, get_row() is usually the better choice instead of get_results(). $zipdetail = $wpdb->get_row( “SELECT * FROM `li_zipcode` WHERE `zip_code` = ‘$zipcode'”, OBJECT ); If $zipcode is coming from an untrusted … Read more

Can’t fetch Custom Post Type Data through Custom Query

Changing my query to following worked for me. I removed the product ID field & called the post taxonomy directly as I didn’t need the product Id’s. <?php $args = array( ‘post_type’ => ‘colorshades’, ‘fields’ => ‘ids’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘colors_product_id’, // ‘value’ => $product->id, // ‘compare’ => ‘=’, … Read more

Combine 2 arrays in a query parameter

This does not work because this is not how you merge two arrays: ‘post__not_in’ => get_upsell_ids(), [get_the_ID()] Instead you need to take those 2 arrays and combine them using array_merge, a standard PHP function: https://www.php.net/manual/en/function.array-merge.php Note that __not_in type parameters have a very high performance cost and do not scale, this query will be very … Read more

Tax Query only returns for the first of several terms

Related issue: Multiple relationship for multiple tax_query in WP_Query The issue here was that mixed multi-relationship lookups are only permitted using the term_taxonomy_ids field in the query, the above worked fine once switched like so: $params = [ “status” => “publish”, “tax_query” => [ [ “taxonomy” => “jewellery_metal”, “field” => “term_taxonomy_id”, “terms” => [ 36, … Read more

Single field to search for matches on post ID or meta values

Use this code instead- $args = array( ‘post_type’ => ‘shop_order’, ‘posts_per_page’ => ‘-1’, ‘post_status’ => array_keys( wc_get_order_statuses() ), ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘_billing_first_name’, ‘compare’ => ‘LIKE’, ‘value’ => $_GET[‘sc’], // you should escape this ), array( ‘key’ => ‘_billing_last_name’, ‘compare’ => ‘LIKE’, ‘value’ => $_GET[‘sc’], // you should escape this … Read more

WP Query ordering on a meta field for posts with a date in the future not ordering by datetime

The docs are a little vague in this area, but it should be possible to define your ordering value more succinctly: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 5, ‘category__in’ => $postCategories, ‘meta_query’ => array( array( ‘key’ => ‘ordering_date’, ‘value’ => date(“Y-m-d H:i:s”), ‘compare’ => ‘>=’, ‘type’ => ‘DATETIME’, ), ), … Read more