Displaying Listing Attribute value in custom modal

I’ve created a custom modal that I am using on Listing pages.

  // Quote Modal Listing - Uses Listing Attributes
    echo ( new HivePress\Blocks\Modal(
        [
            'title'  => 'Contractor Details',
            'name'   => 'quote_modal_listing',
            'blocks' => [
                'listing_title' => [
                    'type'    => 'content',
                    'content' => '<h2 class="hp-listing__title">' . get_the_title() . '</h2>',
                    '_order'  => 100,
                ],
                'listing_phone' => [
                    'type'    => 'content',
                    'content' => '📱 ' . get_post_meta(get_the_ID(), 'hp-listing__attribute--phone', true),
                    '_order'  => 110,
                ],
                'listing_email' => [
                    'type'    => 'content',
                    'content' => '📧 ' . get_post_meta(get_the_ID(), 'hp-listing__attribute--email', true),
                    '_order'  => 120,
                ],
            ],
        ]
    ) )->render();
}
add_action('wp_footer', 'custom_hivepress_modals');

The modal works and the Listing name is displayed as expected, however the listing attribute phone and attribute email do not show any values. I’ve troubleshooted various methods of calling the attributes but Im not really sure what i need to do. Is there a proper way to display the values associated with listing attributes

Hi,

If these are listing attributes, please change hp-listing__attribute--phone to hp_phone and hp-listing__attribute--email to hp_email (if attribute fields are named “phone” and “email”). Another option is using HivePress API:

$listing=hivepress()->request->get_context('listing');

echo $listing->get_phone(); 
echo $listing->get_email();

Hope this helps

1 Like

Thank you. 100% perfect!

1 Like