0

I'm not sure if this is possible - but checking before re-writing the template.

I've extended wp_query to allow for a geocode/location search to be performed. This is working in itself and returning posts in a nearest to search point first order.

In the query generated now by wp_query it's calculating the distance in miles away from the search point and returning this AS distance.

My colleague who's built the results template has used ACF - so is looping through the list using:

<?php while ( have_posts() ) : the_post(); ?>

This 'distance' value is not being returned when using the usual ACF method of <?php echo the_field('distance'); ?> which makes sense as it's not an ACF or post field, but rather calculated in the wp_query...

Is there a good way of accessing values from the query, but not ACF fields, inside this ACF loop - or am I better rewriting to manually look through the query results without the ACF methods?

  • 1
    Isn't that just the regular WP loop? Don't think this is related to ACF, since as you say this distance-thing isn't a custom field and ACF is made for working with those. Not sure how you build this without seeing more code. But couldn't you go something like $post->distance ? – jzatt Jan 23 '15 at 13:29
  • I'm being so dense today - you're right, it's just in $post. If you want to post that as an answer will accept thanks for that. – steve Jan 23 '15 at 13:51
  • Glad it worked for you. Answer posted :) – jzatt Jan 23 '15 at 14:17
1

Isn't that just the regular WP loop? Don't think this is related to ACF, since as you say this distance-thing isn't a custom field and ACF is made for working with those.

Not sure how you build this without seeing more code. But couldn't you go something like $post->distance ?

1

I guess it should work the way it is described in your question of default code for Advance custom fields Also as custom field are part of post you can use $post->name of custom field also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.