Skip to content

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.

$id = $listing->get_id();

exists(): bool

Returns true if the listing was found (non-zero ID).

if ( $listing->exists() ) { ... }

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.

$listing->get( 'id' );
$listing->get( 'dms_focus_keyword' );

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.

$listing->update_meta( 'my_meta_key', 'value' );

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.

$listing->set_post_data( 'post_status', 'publish' );

Identity & Content

get_title(): string

Returns the listing title. Filterable via dms_listing_title.

echo esc_html( $listing->get_title() );

set_title( $title ): WP_Error|bool|int

Updates the listing post title.

$listing->set_title( 'New Title' );

Returns the listing URL. Filterable via dms_listing_permalink.

echo esc_url( $listing->get_permalink() );

get_post_content( int $max_chars = 0, string $ellipsis = '...' ): string

Returns the post content, optionally truncated to $max_chars characters.

echo wp_kses_post( $listing->get_post_content( 200 ) );

Returns the WordPress admin edit URL for the listing.

echo esc_url( $listing->get_edit_link() );

Type & Categories

get_type(): Type

Returns the Type object for this listing's inventory type.

$type = $listing->get_type();
echo esc_html( $type->get( 'plural' ) );

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.

$features = $listing->get_terms( 7 );

Pricing

get_price( string $type = 'price' ): float

Returns the listing price as a float. Pass 'original' to get the pre-discount price.

$price          = $listing->get_price();
$original_price = $listing->get_price( 'original' );

get_formatted_price( string $type = 'price' ): string

Returns the formatted price string (currency symbol, thousands separator, etc.).

echo esc_html( $listing->get_formatted_price() ); // e.g. "$24,995"

set_price( $price ): void

Sets the listing price.

$listing->set_price( 24995 );

set_original_price( $price ): void

Sets the original (pre-discount) price and recalculates the discount amount.

$listing->set_original_price( 29995 );

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'] ) . '">';

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.

$id = $listing->get_main_image_id();

Returns true if the listing has any gallery image data set.

if ( $listing->has_gallery_images() ) { ... }

Status

get_status(): string

Returns the listing's current status slug (e.g. 'active', 'sold', 'sale_pending').

echo esc_html( $listing->get_status() );

set_status( $status ): void

Updates the listing's status.

$listing->set_status( 'sold' );

is_sold(): bool

if ( $listing->is_sold() ) { ... }

set_sold( bool $is_sold ): int|bool

Marks the listing as sold or not. Also clears sale-pending status and records lifecycle events.

$listing->set_sold( true );

is_sale_pending(): bool

if ( $listing->is_sale_pending() ) { ... }

set_sale_pending( bool $is_pending ): int|bool

$listing->set_sale_pending( true );

is_coming_soon(): bool

if ( $listing->is_coming_soon() ) { ... }

is_published(): bool

Returns true if the listing's post status is publish.

if ( $listing->is_published() ) { ... }

is_visible(): bool

Returns true if the listing is not private.

if ( $listing->is_visible() ) { ... }

Leads & Stats

get_total_leads(): int

Returns the total number of leads associated with this listing.

echo $listing->get_total_leads();

get_days_on_lot(): int

Returns the number of days the listing has been (or was) on the lot.

echo $listing->get_days_on_lot();

get_views( $view_type ): int

Returns the view count for a given view type.

echo $listing->get_views( 'vdp' );

Badges & Comparison

get_badge(): string

Returns the rendered HTML for the listing's badge (if any). Respects sold/sale-pending overrides and badge conditions.

echo wp_kses_post( $listing->get_badge() );

set_badge( int $badge_id ): void

Assigns a badge to the listing.

$listing->set_badge( 2 );

remove_badge(): void

Removes the listing's badge assignment.

$listing->remove_badge();

is_compared(): bool

Returns true if this listing is currently in the user's compare cookie.

if ( $listing->is_compared() ) { ... }

get_next_listing()

Returns the URL of the next listing (by publish date).

echo esc_url( $listing->get_next_listing() );

get_prev_listing()

Returns the URL of the previous listing (by publish date).

echo esc_url( $listing->get_prev_listing() );