How to get listing attribute value of a select type programatically?

I usually do like this:

$listing = HivePress\Models\Listing::query()->get_by_id( 123 );
$fieldx_value = $listing->get_fieldx();

It works for general attributes like string or number. But if the attribute type is “select” It returns NULL. How to get it correctly?

Hi,

Please find the answer in this topic:

Please let me know if you need further assistance.

it doesnt work when i use $listing->get_fieldx__name();
Only work if i use $listing->display_fieldx();

Why? Is it a bug?

Providing a specific solution would require us to look at the actual code and debug the attribute type you’re working with, which falls outside our support scope. We can only provide general guidance on this.

If the double underscore method (__name) isn’t working, it’s possible the attribute isn’t a select-type field, since __name should return the display name for selectable attributes. Please note that this returns an array of names, so if you just use echo directly, it will appear empty, you’d need to handle it as an array.

Hope this helps.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.