# Include attachment URL in another attribute's description

**URL:** <https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587>\
**Category:** HivePress\
**Created:** [February 26, 2023, 7:56pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587 "2023-02-26T19:56:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruurdniepoth](https://community.hivepress.io/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@ruurdniepoth](https://community.hivepress.io/u/ruurdniepoth)\
**Post date:** [February 26, 2023, 7:56pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/1 "2023-02-26T19:56:07Z")

</div>

Hi there,

My listing owners have the ability to upload their own booking terms for their listing in pdf format. When clients book their property the client should accept the terms. For that I just added a checkbox that they confirm, but I need an URL to that listing attachment. Not sure what is the best approach. I was thinking to use the %listing.attachment% object in URL format but it does not work. Just prints the text. The URL would be unique for every listing.

 ![image](https://community.hivepress.io/uploads/default/original/2X/3/3f0dfb50731677dad156266555ba8750a1e71602.jpeg)  
 ![image](https://community.hivepress.io/uploads/default/original/2X/0/061497f7c1ee8aa4230e616f368c05462508e645.png)

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [February 27, 2023, 1:17pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/5 "2023-02-27T13:17:53Z")

</div>

Hi,

Unfortunately, there’s no such feature; it would require a custom implementation (this is possible only for Display format).

As a workaround, you can add this information to the general terms (and display a link to the terms on the vendor’s page, in any Display Area).

---

<div class="post-metadata">

**Author:** ![ruurdniepoth](https://community.hivepress.io/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@ruurdniepoth](https://community.hivepress.io/u/ruurdniepoth)\
**Post date:** [February 27, 2023, 5:43pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/6 "2023-02-27T17:43:42Z")

</div>

Thanks for the answer Andrii and the suggested workaround.

I’m familiar with PHP for other projects but still learning on the Wordpress specifics. I like they way everything can be customised as well and the coding practises for Hivepress. Also happy to hire someone at Fiverr at a later stage if required for certain functions if I would not have time.

One question to understand it better and have a lead where to start to customise.

“If I like to refer to an attribute of a listing anywhere from the project/page, how would that look like?”

I assume this would need to have the current “post ID” to “lookup” the attribute.

---

<div class="post-metadata">

**Author:** ![yevhen](https://community.hivepress.io/user_avatar/community.hivepress.io/yevhen/32/23_2.png) [@yevhen](https://community.hivepress.io/u/yevhen)\
**Post date:** [February 28, 2023, 1:40pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/10 "2023-02-28T13:40:03Z")

</div>

Please try this PHP snippet

Please change `put_your_checkbox_attribute_field_name` on your booking checkbox attribute field name and please change `get_put_your_url_attribute_field_name` on `get_ + listing URL attribute field name`

```auto
add_filter(
	'hivepress/v1/forms/booking_confirm',
	function($form_args, $form){
		$booking = $form->get_model();
		
		if(!$booking){
			return $form_args;
		}
		
		$listing = $booking->get_listing();
		
		if(!$listing || !$listing->get_put_your_url_attribute_field_name()){
			return $form_args;
		}
		
		if(isset($form_args['fields']['put_your_checkbox_attribute_field_name'])){
			$form_args['fields']['put_your_checkbox_attribute_field_name']['description'] = '<a href="'.esc_url($listing->get_put_your_url_attribute_field_name()).'" target="_blank">Custom text</a>';
		}
		
		return $form_args;
	},
	1000,
	2
);

```

---

<div class="post-metadata">

**Author:** ![ruurdniepoth](https://community.hivepress.io/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@ruurdniepoth](https://community.hivepress.io/u/ruurdniepoth)\
**Post date:** [February 28, 2023, 2:45pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/11 "2023-02-28T14:45:17Z")

</div>

Thanks Yevhen,

That’s something I’m looking for, however does not work yet. I was trying to directly refer to the attachment attribute URL for the custom post type. It looks like HP is saving a field ID for the attachment as listing attachments are saved in the media gallery. I was onto this, which does not return anything until you shared the filter which would be better.

```auto
<?php
$listing_id = get_the_ID();
$attachment_ids = get_post_meta($listing_id, '_hivepress_listing_attachments', true);
if ($attachment_ids) {
  foreach ($attachment_ids as $attachment_id) {
    $attachment_url = wp_get_attachment_url($attachment_id);
    echo '<a href="' . $attachment_url . '">' . $attachment_url . '</a><br />';
  }
}
?>

```

You filter does not generate the correct URL as **the attribute is of the _Field Type Attachment_, not an URL type**. Not sure how to fetch the URL.

Here is the listing attribute. To be clear, every listing will have an PDF uploaded which I like to lookup to URL from. Something like $listing-\>attachment\_attribute-\>URL.

I think I’m close 😉

 ![image](https://community.hivepress.io/uploads/default/original/2X/3/3e2a1ccd77773c08f2fd14ae7cfc2230aa3ec808.png)

---

<div class="post-metadata">

**Author:** ![ruurdniepoth](https://community.hivepress.io/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@ruurdniepoth](https://community.hivepress.io/u/ruurdniepoth)\
**Post date:** [February 28, 2023, 4:32pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/12 "2023-02-28T16:32:58Z")

</div>

Hi again,

I further investigated to pull the data and by combining the `wp_get_attachment_url()` with the listing attachment attribute field value to lookup the URL. See the solution below in the filter.

Would you agree this is a solid solution?

```auto
add_filter(
	'hivepress/v1/forms/booking_confirm',
	function($form_args, $form){
		$booking = $form->get_model();
		
		if(!$booking){
			return $form_args;
		}
		
		$listing = $booking->get_listing();
		
		if(!$listing || !$listing->get_put_your_url_attribute_field_name()){
			return $form_args;
		}
		
		$field_name = 'hp_algemene_voorwaarden'; // replace my_custom_field with the name of your custom field
		$attachment_post_id = $listing->get_algemene_voorwaarden();
		$attachment_url = wp_get_attachment_url( $attachment_post_id );
		echo $attachment_url;
		
		if(isset($form_args['fields']['algemene_voorwaarden'])){
			$form_args['fields']['algemene_voorwaarden']['description'] = '<a href="'.esc_url($attachment_url).'" target="_blank" rel="noopener">Custom text</a>';
		}
		
		return $form_args;
	},
	1000,
	2

```

---

<div class="post-metadata">

**Author:** ![yevhen](https://community.hivepress.io/user_avatar/community.hivepress.io/yevhen/32/23_2.png) [@yevhen](https://community.hivepress.io/u/yevhen)\
**Post date:** [March 1, 2023, 4:08pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/14 "2023-03-01T16:08:43Z")

</div>

Yes, it seems like the possible way to get the attachment URL

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [March 31, 2023, 4:08pm UTC](https://community.hivepress.io/t/include-attachment-url-in-another-attributes-description/4587/15 "2023-03-31T16:08:45Z")

</div>

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