Listing¶
Namespace: DMS\Listing Obtained via: dms_get_listing()
Represents a single inventory listing. Wraps the underlying WP_Post object and provides typed accessors for listing-specific meta, categories, pricing, images, and status.
Core¶
get_id(): int¶
Returns the listing post ID.
exists(): bool¶
Returns true if the listing was found (non-zero ID).
get( string $name, mixed $default_value = null ): mixed¶
Generic property getter. Checks public properties, then the $data array (loaded meta). Returns $default_value if not found.
get_meta( string $key, bool $is_single = true ): mixed¶
Retrieves raw post meta. Uses the pre-loaded raw_data array to avoid extra DB calls.
$value = $listing->get_meta( 'my_meta_key' );
// Multi-value meta
$values = $listing->get_meta( 'my_meta_key', false );
update_meta( string $key, string|int|array $value ): void¶
Updates a post meta value and keeps the in-memory raw_data in sync. Category meta keys (dms_category_*) trigger automatic term count adjustments.
get_post_data( string $name ): mixed¶
Returns a field from the underlying WP_Post object.
$status = $listing->get_post_data( 'post_status' );
$post_date = $listing->get_post_data( 'post_date' );
set_post_data( string $name, string $value ): WP_Error|bool|int¶
Updates a field on the underlying WP_Post object via wp_update_post(). Also fires lifecycle events for post_status changes.
Identity & Content¶
get_title(): string¶
Returns the listing title. Filterable via dms_listing_title.
set_title( $title ): WP_Error|bool|int¶
Updates the listing post title.
get_permalink(): string¶
Returns the listing URL. Filterable via dms_listing_permalink.
get_post_content( int $max_chars = 0, string $ellipsis = '...' ): string¶
Returns the post content, optionally truncated to $max_chars characters.
get_edit_link(): ?string¶
Returns the WordPress admin edit URL for the listing.
Type & Categories¶
get_type(): Type¶
Returns the Type object for this listing's inventory type.
get_term( int $category_id, bool $full_term = false ): string|array|Term¶
Returns the listing's value for a given category. Returns the term string by default; pass $full_term = true for the full Term object.
// Term string
$make = $listing->get_term( 3 );
// Full Term object
$term = $listing->get_term( 3, true );
echo esc_html( $term->get( 'slug' ) );
get_terms( int $category_id, bool $full_term = false ): array¶
Returns all term values for a multi-select category.
Pricing¶
get_price( string $type = 'price' ): float¶
Returns the listing price as a float. Pass 'original' to get the pre-discount price.
get_formatted_price( string $type = 'price' ): string¶
Returns the formatted price string (currency symbol, thousands separator, etc.).
set_price( $price ): void¶
Sets the listing price.
set_original_price( $price ): void¶
Sets the original (pre-discount) price and recalculates the discount amount.
Images¶
get_main_image( string $image_size = 'dms-listing-main' ): array¶
Returns an array of image data for the main gallery image.
Array keys: id, src, width, height, alt, caption, data
$image = $listing->get_main_image();
echo '<img src="' . esc_url( $image['src'] ) . '" alt="' . esc_attr( $image['alt'] ) . '">';
get_gallery_images( string $image_size = 'full', bool $show_not_found = true, mixed $filter_category = false ): array¶
Returns all gallery images. Each entry contains id, src, width, height, alt, caption, data. Videos and code slides include additional keys.
$images = $listing->get_gallery_images();
foreach ( $images as $image ) {
echo '<img src="' . esc_url( $image['src'] ) . '">';
}
// Filter to a specific image category by ID or slug
$exterior = $listing->get_gallery_images( 'full', true, 'exterior' );
get_main_image_id(): int¶
Returns the attachment ID of the main image.
has_gallery_images(): bool¶
Returns true if the listing has any gallery image data set.
Status¶
get_status(): string¶
Returns the listing's current status slug (e.g. 'active', 'sold', 'sale_pending').
set_status( $status ): void¶
Updates the listing's status.
is_sold(): bool¶
set_sold( bool $is_sold ): int|bool¶
Marks the listing as sold or not. Also clears sale-pending status and records lifecycle events.
is_sale_pending(): bool¶
set_sale_pending( bool $is_pending ): int|bool¶
is_coming_soon(): bool¶
is_published(): bool¶
Returns true if the listing's post status is publish.
is_visible(): bool¶
Returns true if the listing is not private.
Leads & Stats¶
get_total_leads(): int¶
Returns the total number of leads associated with this listing.
get_days_on_lot(): int¶
Returns the number of days the listing has been (or was) on the lot.
get_views( $view_type ): int¶
Returns the view count for a given view type.
Badges & Comparison¶
get_badge(): string¶
Returns the rendered HTML for the listing's badge (if any). Respects sold/sale-pending overrides and badge conditions.
set_badge( int $badge_id ): void¶
Assigns a badge to the listing.
remove_badge(): void¶
Removes the listing's badge assignment.
is_compared(): bool¶
Returns true if this listing is currently in the user's compare cookie.
Navigation¶
get_next_listing()¶
Returns the URL of the next listing (by publish date).
get_prev_listing()¶
Returns the URL of the previous listing (by publish date).