# How to get the resource's ID from the returned uri?

**URL:** <https://community.modx.com/t/how-to-get-the-resources-id-from-the-returned-uri/3805>\
**Category:** General\
**Created:** [March 15, 2021, 5:01pm UTC](https://community.modx.com/t/how-to-get-the-resources-id-from-the-returned-uri/3805 "2021-03-15T17:01:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffsydor](https://community.modx.com/user_avatar/community.modx.com/jeffsydor/32/363_2.png) [@jeffsydor](https://community.modx.com/u/jeffsydor)\
**Post date:** [March 15, 2021, 5:01pm UTC](https://community.modx.com/t/how-to-get-the-resources-id-from-the-returned-uri/3805/1 "2021-03-15T17:01:04Z")

</div>

I’m wondering if there is a way to find the ID of a resource based solely on the uri passed?

For example, my internal search engine is picking up pages that are temporarily linked to other pages by means of the Weblink Resource Type. So **Resource A** , is showing up in my search results with a description of **Resource B’s** uri. Whereas **Resource A’s** content is [[~22]].

What I was considering was using FastField to pull the content of **Resource B** in for the description of **Resource A**. Is this possible to even do? This is what I had so far:

In my chunk:

> ```
> [[+resource_type:contains=`modweblink`:then=`
> <div class="result">
> <div class="pagetitle"><a href="[[+uri]]">[[+pagetitle]] (the weblink)</a></div>
> <div class="content">[[+content:ContentID]]</div>
> </div>
> `:else=`
> <div class="result">
> <div class="pagetitle"><a href="[[+uri]]">[[+pagetitle]]</a></div>
> <div class="content">[[+content:prepareContent]]</div>
> </div>
> `]]
> 
> ```

In the ContentID snippet (currently is only displaying the rendered uri):

> ```
> <?php
> $resourceID = $modx->findResource($input);
> return $resourceID;
> 
> ```

I was hoping that I could return the ID (22) from the $input to then put into a FastField of **[[#[[+content:ContentID]].content]]**. Or is this way overthinking it?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [March 15, 2021, 8:15pm UTC](https://community.modx.com/t/how-to-get-the-resources-id-from-the-returned-uri/3805/2 "2021-03-15T20:15:19Z")

</div>

Maybe the variable `$input` has still the value `[[~22]]` when the snippet `ContentID` is called.  
You could test if this works:

```auto
<?php
$search_pattern="/\[\[~(\d+)\]\]/";
if (preg_match($search_pattern, $input, $match)){
    return $match[1];
} else {
    return $input;
}

```

---

<div class="post-metadata">

**Author:** ![jeffsydor](https://community.modx.com/user_avatar/community.modx.com/jeffsydor/32/363_2.png) [@jeffsydor](https://community.modx.com/u/jeffsydor)\
**Post date:** [March 15, 2021, 9:21pm UTC](https://community.modx.com/t/how-to-get-the-resources-id-from-the-returned-uri/3805/3 "2021-03-15T21:21:11Z")

</div>

You were right! thank you for that idea!
