Closed nickcernis closed 5 years ago
The _listing_price_sortable key is being removed when saving a listing:
_listing_price_sortable
https://wordpress.org/support/topic/version-1-3-2-removing-meta_key-_listing_price_sortable/
New listings and edited listings may fail to appear in search results, archives, or other lists if _listing_price_sortable has been used in the query to select or order them.
The paid plugin Extended AgentPress Listings Widget apparently allows sorting by _listing_price_sortable, for example.
git checkout 1.3.1
_listing_price
❯ wp post meta list 7488 +---------+-------------------------+--------------+ | post_id | meta_key | meta_value | +---------+-------------------------+--------------+ | 7488 | _edit_last | 1 | | 7488 | _edit_lock | 1562778936:1 | | 7488 | _listing_price | 12345 | | 7488 | _listing_price_sortable | 12345 | +---------+-------------------------+--------------+
git checkout 1.3.2
The _listing_price_sortable row will now be missing:
❯ wp post meta list 7488 +---------+----------------+--------------+ | post_id | meta_key | meta_value | +---------+----------------+--------------+ | 7488 | _edit_last | 1 | | 7488 | _edit_lock | 1562779081:1 | | 7488 | _listing_price | 12345 | +---------+----------------+--------------+
Fixed for me by changing these lines in agentpress-listings/includes/class-agentpress-listings.php:
agentpress-listings/includes/class-agentpress-listings.php
- if ( isset( $property_details['_listing_price'] ) && ! empty( $property_details['_listing_price'] ) ) { + if ( isset( $property_details[0]['_listing_price'] ) && ! empty( $property_details[0]['_listing_price'] ) ) { - $price_sortable = preg_replace( '/[^0-9\.]/', '', $property_details['_listing_price'] ); + $price_sortable = preg_replace( '/[^0-9\.]/', '', $property_details[0]['_listing_price'] ); update_post_meta( $post_id, '_listing_price_sortable', floatval( $price_sortable ) ); } else { delete_post_meta( $post_id, '_listing_price_sortable' ); }
New posts and posts that were edited would then have to be re-saved after this fix in order to restore the _listing_price_sortable.
The $property_details data structure changed here in 1.3.2:
$property_details
https://github.com/studiopress/agentpress-listings/blob/cd47ad2c84fe71bd7abc600567bf7bfca6270b1e/includes/class-agentpress-listings.php#L219
And we missed that $property_details needed to become $property_details[0] at all points below that in the code, rather than just the for loop.
$property_details[0]
The
_listing_price_sortable
key is being removed when saving a listing:https://wordpress.org/support/topic/version-1-3-2-removing-meta_key-_listing_price_sortable/
Impact
New listings and edited listings may fail to appear in search results, archives, or other lists if
_listing_price_sortable
has been used in the query to select or order them.The paid plugin Extended AgentPress Listings Widget apparently allows sorting by
_listing_price_sortable
, for example.To reproduce
git checkout 1.3.1
_listing_price
and_listing_price_sortable
:git checkout 1.3.2
The
_listing_price_sortable
row will now be missing:To fix
Fixed for me by changing these lines in
agentpress-listings/includes/class-agentpress-listings.php
:New posts and posts that were edited would then have to be re-saved after this fix in order to restore the
_listing_price_sortable
.Cause
The
$property_details
data structure changed here in 1.3.2:https://github.com/studiopress/agentpress-listings/blob/cd47ad2c84fe71bd7abc600567bf7bfca6270b1e/includes/class-agentpress-listings.php#L219
And we missed that
$property_details
needed to become$property_details[0]
at all points below that in the code, rather than just the for loop.