# Calling tainacan\_the\_metadata function outside the loop

**URL:** <https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758>\
**Category:** Suporte\
**Tags:** metadados\
**Created:** [Fevereiro 14, 2024, 3:38pm UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758 "2024-02-14T15:38:07Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![mateus.m.luna](https://yyz2.discourse-cdn.com/free1/user_avatar/tainacan.discourse.group/mateus.m.luna/32/3_2.png) [@mateus.m.luna](https://tainacan.discourse.group/u/mateus.m.luna)\
**Post date:** [Fevereiro 26, 2024, 6:18pm UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758/21 "2024-02-26T18:18:51Z")

</div>

> [@argeifontesfunes](#):
>
> returns nothing inside the loop

Ok, we need to investigate this. What about a `var_dump` to `tainacan_get_collection`? Or, since you are obtaining the collection ID from the current post type, `tainacan_the_collection_name($my_collection_id)`?

> [@argeifontesfunes](#):
>
> When I was talking about the exposer, I meant the situation when in list of items page, a user clicks on “See as” and wnat to get all the items of a page (see photo). I would love the user to be able to download a file with that list as it happens with CSV exposer.

Ok, now I got it. I believe what does the trick for the CSV exposer is this line:

> <https://github.com/tainacan/tainacan/blob/855e6f19ab5925cbe816b41eea2c2c9e8bd72d01/src/classes/exposers/class-tainacan-csv.php#L47>

Can you try putting the same logic in your exposer? It should be in your `rest_request_after_callbacks` function. I would also advise adding the file formar as in line 45 up there.

---

<div class="post-metadata">

**Author:** ![argeifontesfunes](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@argeifontesfunes](https://tainacan.discourse.group/u/argeifontesfunes)\
**Post date:** [Fevereiro 26, 2024, 8:12pm UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758/22 "2024-02-26T20:12:19Z")

</div>

Dear Mateus:

I have just seen that there is a new version of Tainacan. Can you confirm that this version resolves the issue about the sections title that we discussed in December and for which you sent me a version of the plugin?

Unfortunately, your two suggestions did not work. When including these lines in the template,

```
           > //Post's collection id

```

> ```
> //$collection = tainacan_get_collection_id();
> $collection = get_post_type();
> preg_match('/\d+/', $collection, $matches);
> $collection_id = $matches[0];
> 
> //Post's collection name
> $collection_name = tainacan_the_collection_name($collection_id);
> 
> ```

the $collection-name variable returns an empty string.

And when adding these lines to the `rest_request_after_callbacks` function,

```
    > public function rest_request_after_callbacks( $response, $handler, $request ) {

```

> ```
> $response->set_headers( ['Content-Type: text/plain; charset=' . get_option( 'blog_charset' )] );
> 
> $filename .= 'funes.ris';
>     
> header('Content-Disposition: attachment; filename="'.$filename.'"');
> 
> ```

I still get a new page with string coming from the $response variable, instead of having the browser download a file with it.

Best regards,

```
                    Pedro

```

---

<div class="post-metadata">

**Author:** ![argeifontesfunes](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@argeifontesfunes](https://tainacan.discourse.group/u/argeifontesfunes)\
**Post date:** [Fevereiro 27, 2024, 11:51am UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758/23 "2024-02-27T11:51:47Z")

</div>

Dear Mateus:

It is always better to let things rest overnight. I managed to solve the download issue with what looks as the same code I was using yesterday:

> ```
> $response->set_headers( ['Content-Type: text/plain; charset=' . get_option( 'blog_charset' )] );
>          
> //Set to download
> $filename = 'Funes.ris';
> header('Content-Disposition: attachment; filename="'.$filename.'"');
> 
> ```

Thank you again for your help.

I have seen that tainacan is not available in Wordpress plugins. Is there anything we should be worried?

Best regards,

```
                    Pedro

```

---

<div class="post-metadata">

**Author:** ![mateus.m.luna](https://yyz2.discourse-cdn.com/free1/user_avatar/tainacan.discourse.group/mateus.m.luna/32/3_2.png) [@mateus.m.luna](https://tainacan.discourse.group/u/mateus.m.luna)\
**Post date:** [Fevereiro 27, 2024, 1:59pm UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758/24 "2024-02-27T13:59:08Z")

</div>

> [@argeifontesfunes](#):
>
> It is always better to let things rest overnight. I managed to solve the download issue with what looks as the same code I was using yesterday:

That is some true right there 🤣

> [@argeifontesfunes](#):
>
> I have seen that tainacan is not available in Wordpress plugins. Is there anything we should be worried?

Don’t worry, it was a temporary Download removal as it was found a way of accessing the import and export log files without some capabilities check… WordPress is pretty rigorous about its hosted plugins once they start getting more users and sometimes we end up finding this breaches. We already fixed the issue yesterday and are awaiting their review, which tends to last one to three days. Hopefully all should be back to normal soon 🤞.

* * *

About your code being “not efficient” or “messy”. I do enjoy that you could learn a lot in the process, even being a bit of a headache, it is important that other contributors start putting their hands on code. I really cannot offer a more detailed review of these requests because we’ve been overloaded with demands that impact all users (the security review aforementioned being one of them). But hopefully, as your usage increase, you can find more time to mature the code. We often launch things one way and later discover better ways to do it.

The ideal path, in my opinion is that one day you can convert your plugin into an actual plugin for the repository. We could think of strategies to parameterize all those metadata in a way that it can work for other collections or even other citation standards. It is surely something that other users could benefit from ❤

---

<div class="post-metadata">

**Author:** ![argeifontesfunes](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@argeifontesfunes](https://tainacan.discourse.group/u/argeifontesfunes)\
**Post date:** [Fevereiro 27, 2024, 2:30pm UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758/25 "2024-02-27T14:30:50Z")

</div>

Dear Mateus:

Thank you for your comments. In our first email conversation early in December 2023, you told me that Tainacan was not a “swiz-knife” solution for every problem. Anyway, I liked so much the plugin, knowing that it was not designed for bibliographic repositories. The view and the exposers in my plugin cover the basic needs for that purpose that were not available in Tainacan. The only issue remaining is the authors’ order. I had to add a field to register the authors in the proper order.

I will switch now my work on adding several other collections we have in queue.

My final concern now is going from staging to production. We are having big problems doing that given the size of database: 2 Gb. I have seen some forum messages concerning this, but my IT department is a little bit mind closed.

I hope, one day, we can offer the plugin to other users needing to implement a bibliographic repository.

Best regards,

```
                    Pedro

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/tainacan/original/1X/7a4cda66d79553ef5eebf93769c00bdba65e7ab2.png) [@system](https://tainacan.discourse.group/u/system)\
**Post date:** [Abril 27, 2024, 2:31pm UTC](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758/26 "2024-04-27T14:31:27Z")

</div>

Este tópico foi fechado automaticamente 60 dias depois da última resposta. Novas respostas não são mais permitidas.

[Página anterior](https://tainacan.discourse.group/t/calling-tainacan-the-metadata-function-outside-the-loop/1758.md?page=1)
