Find metadata slugs?

hi, a very basic question. I can find the IDs for the metadata I create for my collection, but I don’t see the slugs anywhere. Where can I find the slugs?

Hi @AronAmbrosiani!

In which context are you looking for them? Would it be a in the UI in the admin panel or are you looking for them via a function in the PHP?

One thing I can say is that the tainacan_get_the_metadata() function accepts an argument display_slug_as_class that does what it says and may be useful to style the way that they appear in the frontend, if that is what you are looking for.

hi @mateus.m.luna, I’m fetching photographer metadata to display together with the document of an item (in childtheme/template-parts/single-items-document.php). Right now I’m using IDs but slugs would be easier to understand for the next person looking at the code.

<?php $args = array( 'before_value' => '

', 'after_value' => '

', 'metadata__in' => [411, 415] ); tainacan_the_metadata( $args ) ?>

Uhmm I see. Unfortunately, there is no function focused on this task, as long as I remember. You could still fetch the entire metadata objects and get the slug from them:

$metadata_slugs = []; 
if ($collection = $this->get_current_collection_object() ) {
    $metadata = $collection->get_metadata();
    foreach ($metadata as $metadatum) {
	    $metadata_slugs[] = $metadatum->slug; 

Then you can use this array to decide what to pass to the tainacan_the_metadata, which gets the item metadata.

If by photographer you mean an item from another collection, thought, you could solve this easily with relationship metadata. You can take advantage of the “Detailed item relationship” feature, released last version:

Ah, sounds good, that sounds like a more flexible solution. I’ll look into it!

1 Like