I have a custom field which I set in a var
$customCoords = usp_get_meta(false, 'usp-custom-90');
That custom field has a string like this:
45.46135436613811,9.175124650000043
Then I get some values from a form:
$lat = $_GET['usp-custom-19'];
$ln = $_GET['usp-custom-20'];
And I join them like this:
$coordinates = $ln . "," .$lat;
Now $coordinates
is a string like this:
45.46135436613811,9.175124650000043
And now I want to query all posts which have the same exact string as $coornidates
and I do
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => $customCoords,
'value' => $coordinates,
'compare' => '=',
'type' => 'CHAR'
)
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo the_title();
echo "<br>";
}
}
But I get nothing.
UPDATE
$lat = $_GET['usp-custom-19'];
$ln = $_GET['usp-custom-20'];
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$customCoords = usp_get_meta(false, 'usp-custom-90');
$arrayCoords = explode( ",", $customCoords );
$radiusLn = +$arrayCoords[0] + 10;
$radiusLat = +$arrayCoords[1] + 10;
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'relation' => 'AND',
array(
'key' => 'get_usp-custom-19',
'value' => array($ln, $radiusLn),
'compare' => '>='
),
array(
'key' => 'get_usp-custom-20',
'value' => array($lat, $radiusLat),
'compare' => '<='
),
),
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
the_title();
}
}
}
}