Copy Listing Attributes to Request Attributes

Hello all, I am trying to copy one specific attribute I have set up in Listings to Requests attributes. This attribute has 10 checkbox categories within.

I am trying with the following code but it’s not working.

function duplicate_service_offered_attribute() {
    if ( function_exists( 'hivepress' ) ) {
        $attributes = hivepress()->get_attributes();

        // Get the existing "Service Offered" attribute
        $existing_attribute = $attributes->get( 'service_offered' );

        if ( $existing_attribute ) {
            // Clone the attribute and modify its properties
            $new_attribute = $existing_attribute;
            $new_attribute['name'] = 'Requested Service'; // New attribute name
            $new_attribute['slug'] = 'requested_service'; // Unique slug
            $new_attribute['listing_section'] = 'requests'; // Assign to requests

            // Register the new attribute
            $attributes->set( 'requested_service', $new_attribute );
        }
    }
}
add_action( 'init', 'duplicate_service_offered_attribute' );

Any leads?

thank you

Hi,

There’s no such function in HivePress:

hivepress()->get_attributes()

Please share more details about the issue, do you want to sync options between listing/request attributes with the same name and of Checkboxes type? If so, the easiest way would be adding the same options manually for both attributes, if you don’t plan to change them often. If syncing is needed, you can try this code to fetch a list of listing attributes:

hivepress()->attribute->get_attributes('listing')

Hope this helps

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