OK, I added distance as custom field to allow me order them using wp_query orderby method!
function add_distance_as_customfield($posts){
$longDest = $_GET['lng'];
$latDest = $_GET['ltd'];
foreach ($posts as $post) {
$placeLocation= get_field('location',$post->ID);
$longPlace =$placeLocation['lng'];
$latPlace = $placeLocation['lat'];
$distance=getDistance($latDest,$longDest,$latPlace,$longPlace);
if ( ! add_post_meta($post->ID, "distance", $distance,true ) ) {
update_post_meta( $post->ID, "distance", $distance );
}
}
}
Related Posts:
- get_pages() not ordering as it should
- Rearrange elements outputted by comment_form()
- Custom column sorting in WordPress admin post table
- Advanced Custom Fields: Sorting custom columns with custom fields sorts only by date
- Sort posts by multiple meta key values
- OrderBy multiple custom meta fields
- Order posts with a custom field but also without
- Rename WooCommerce sorting dropdown options [closed]
- Custom Taxonomy Sort For a Custom Query
- where is admin footer?
- Send default WooCommerce email when switching from custom order status
- Pre_Get_Posts order DESC not registering
- Sort Search Results in Order of/by Character @ count (9) of post(s) title. (Ocean-WP theme)
- Custom product sorting archive page
- Best Practices for Regression Testing WordPress Websites?
- Custom Walker: how to get ID in function start_lvl
- ORDER BY custom field value
- Sorting: custom query with orderby meta_value_num THEN by title
- How to include own css on wordpress tinymce editor?
- What is true chmod for WordPress?
- wp_trim_words() does not trim the_content() in WordPress
- How can I create an alternative home page?
- Gallery Shortcode: using link attribute to link to a specific image size
- Custom Post type sort order not working in the admin area
- get_theme_mod(); returns nothing
- Limit comments displayed on basis of user_id
- Customizer image control default value showing in customizer but not on frontend
- Change default status and replace the icon for an hamburger menu
- How to Register and Display Widget for Custom taxonomy
- How to access my php page in wordpress
- How to display post title & excerpt when mouse hovers on an image?
- How to fix the IE9/WordPress Twenty Ten Header Image Display Problem?
- Automatically add image caption with values from a post parent field?
- How to change email address used for registrations?
- Search result page redirect ex.com/?s=searchterms to ex.com/searchterms
- Add styles with wp_add_inline_style only if modifications exist wp_add_inline_style
- Add custom field to woocommerce variations [closed]
- I want to submit multiple users if checkbox is checked
- How would you implement a CTA infront of a videoplayer? [closed]
- need help with a user-specific custom page template
- How can I get the custom post type assigned to a current custom taxonomy for query?
- $wpdb->replace: WHERE?
- Alphabetical Custom Menu
- Unable to edit the “customize” section and the “widget” section is populating unknown code
- Can’t receive $args[ ] to my custom widget
- Creating custom database table with crud operation
- Can I create my own custom Attachment Display Setting?
- How to sort posts in a custom post type by title in ascending order by default?
- What WordPress Hook Is Used Before Signup Data is Saved?
- One WordPress install for main site at domain.com and blog at blog.domain.com?
- How to locate where an element is generated?
- Combine two conditions in one statement syntax [closed]
- Is there a way to add a new value into a stored custom field value?
- Custom post type sorting: alphabetical order
- Custom Loop Query For Search Page
- spaces in a text
- How can I add interactive python console to my website? [closed]
- Show “Read more” link only when inserted manually
- Customizing Users in Admin Area
- create Custom field for tv series
- Data won’t save if metabox within conditional in admin. What am I missing?
- Restrict Viewing of post on both front and backend?
- Good way to customize admin CSS?
- Add table to WordPress database
- get_delete_post_link( $post->ID ) is blank when logged in as “subscriber”
- Menu not appearing in custom theme
- How can i display custom menu in sidebar?
- Custom select query two tables by a meta key
- How to redirect the home page to a custom page?
- How to Add Additional Search Button?
- WordPress pagination with custom post type?
- How to replace blog page url with subdomain at all places, even in xml sitemap?
- Add array of post id’s to a category?
- How to create social Share Buttons Without Plugin
- Make the home page template my archive/category page template without code duplication
- remove screenshot.png via dashboard
- Saving of Draft is failing
- Custom Avatars for WordPress Comments VIA Website URL?
- Multiple sorting criteries (order by)
- Combine Categories & Custom Taxonomy
- Build custom pdf from users choices
- Show Header When Not In Iframe
- Background setting isn’t applied to entire sidebar height
- Changing a setting in the wp-admin/customize.php reverts CSS styles to parent theme [closed]
- Function to query by custom field and category
- Confused about customising widgets
- Custom user fields validation on registration
- Changes in comments.php in the child theme does not show up on the site
- Share user access between two wordpress sites
- how to modify request to get_template_part()?
- Adding page Title in a custom coded page
- Getting Custom Field value in WP_Query
- Adding Custom HTML/CSS/JS code in specific page
- Custom template not working for existing pages [closed]
- Loop display only 5 posts
- Help needed renaming custom post
- Background image no more visible in the preview
- I need to make the title of the page dynamic in my custom plugin
- Custom CSS working on home page but not on NEW created PAGE
- Custom Menu (only showing direct cildren) ACF not showing