# add dynamic page link to a button

**URL:** <https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [August 16, 2018, 7:40am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360 "2018-08-16T07:40:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wardauae1001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wardauae1001/32/5754_2.png) [@wardauae1001](https://forum.wixstudio.com/u/wardauae1001)\
**Post date:** [August 16, 2018, 7:40am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/1 "2018-08-16T07:40:18Z")

</div>

hello everyone  
I want to add dynamic page link to a button… I did like this but it is still not working …  
when I click the button it must check the collection and get the user email , then add it in the link… however the button is not working

![](https://us1.discourse-cdn.com/wix/original/3X/d/3/d344927bfbff85def98fc545e24fc334c9fe0928.png)  
the code is like this :

import wixUsers **from** ‘wix-users’;  
import wixData **from** ‘wix-data’;  
import wixLocation **from** ‘wix-location’;

export function button1\_click(event, $w) {

```
wixData.query("student")  

```

.find()  
.then( (results) =\> {  
**let** firstItem = results.items[0];

wixLocation.to(`/student/info/`+firstItem.pemail);

} )  
. **catch** ( (err) =\> {  
**let** errorMsg = err;  
} );

}

---

<div class="post-metadata">

**Author:** ![mhammouz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mhammouz/32/4033_2.png) [@mhammouz](https://forum.wixstudio.com/u/mhammouz)\
**Post date:** [August 16, 2018, 8:46am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/2 "2018-08-16T08:46:22Z")

</div>

**Hi Warda,**

Few things you should be aware of:  
First, Be sure that the link path for the dynamic page is correct.  
Second, i think you are missing the most important part in your query, which is the **current user** that you want his Email, because in your code seems to return always the first item from the database, Right?

So what you should do is to add a query that finds the current user then get his email then you can added to the link 🙂

For more information, check this Wix Api - [HERE](https://www.wix.com/code/reference/wix-data.html#query)

Hope this helps!

Best,  
**Mustafa**

---

<div class="post-metadata">

**Author:** ![wardauae1001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wardauae1001/32/5754_2.png) [@wardauae1001](https://forum.wixstudio.com/u/wardauae1001)\
**Post date:** [August 17, 2018, 6:22am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/3 "2018-08-17T06:22:12Z")

</div>

hello @mhammouz  
thanks for your help,

I changed the code , I think it’s better to get the current user’s email instead of checking the database so I make it like this but it is still not working , can you please tell me where is the problem?

export function button1\_click() {  
//Add your code for this event here:

**let** user = wixUsers.currentUser;  
user.getEmail()  
.then( (email) =\> {  
**let** userEmail = email;

wixLocation.to(`/student/info/userEmail`);  
} );  
}

I get this error that the page is not here and in the url instead of the current user’s email I just get (userEmail) word

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/9/d9f41de14407ffb2230ef7fc8b85ce69f54908f9.png)

---

<div class="post-metadata">

**Author:** ![wardauae1001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wardauae1001/32/5754_2.png) [@wardauae1001](https://forum.wixstudio.com/u/wardauae1001)\
**Post date:** [August 17, 2018, 1:18pm UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/4 "2018-08-17T13:18:01Z")

</div>

I solved the problem :  
instead of writing the UserEmail in the string  
[wixLocation.to](http://wixlocation.to/) (`/student/info/userEmail`);

it must be like this:-

[wixLocation.to](http://wixlocation.to/) (`/student/info/’ + userEmail);

🙂

---

<div class="post-metadata">

**Author:** ![ajithkrr](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ajithkrr/32/20520_2.png) [@ajithkrr](https://forum.wixstudio.com/u/ajithkrr)\
**Post date:** [August 2, 2020, 10:44am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/5 "2020-08-02T10:44:26Z")

</div>

It is not – [wixLocation.to](http://wixlocation.to/) (`/student/info/’ + userEmail);

It is – [wixLocation.to](http://wixlocation.to/) (`/student/info/` + userEmail);

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [August 2, 2020, 11:30am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/6 "2020-08-02T11:30:13Z")

</div>

Eagle-eye-Ajit! 😁  
But what you did not see is the DATE of this post ^^

I don’t think taht the post-opener still wants to know the aswer/solution.😁

---

<div class="post-metadata">

**Author:** ![ajithkrr](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ajithkrr/32/20520_2.png) [@ajithkrr](https://forum.wixstudio.com/u/ajithkrr)\
**Post date:** [August 7, 2020, 4:32am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/7 "2020-08-07T04:32:12Z")

</div>

@russian-dima😅😅

---

<div class="post-metadata">

**Author:** ![kzw48914](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@kzw48914](https://forum.wixstudio.com/u/kzw48914)\
**Post date:** [August 8, 2020, 11:41am UTC](https://forum.wixstudio.com/t/add-dynamic-page-link-to-a-button/1360/8 "2020-08-08T11:41:39Z")

</div>

i am new at wix i want to create a custom button which will lead users to another website blog section in sidebar but i don [,](https://minecraftapk.info/) t know how to do so should i hire someone to do so becasue it require HTML
