Get Record by title

Sounds simple: I know the title of a record – how do I get the id#?

$item=get_records('Item', array('title'=>"$text"));

But that doesn’t seem to work…

There’s a couple ways, but I don’t want to over complicate. Could you tell more about where in the theme or plugin you want to dig this up? Depending on the details, the $item and hence its id might be easily available – just depends on where you want this to happen.

I’m experimenting – my users enter an author name and I have another item of that author and want to link them via the name – was trying this method to work around several issues, like the face that there might be multiple authors (so it can’t be a collection), and I need more date (an image, text, etc) than a tag would provide…

Specifically in themes: common/meta-data.php something like (but this doesn’t work):

if($setName=='Audio Item Type Metadata' && $elementName=='Performer')
      $tr=get_records('Item', array('title'=>"$text"));
      foreach($tr AS $onetr)
          echo "$onetr[id] -$text- $onetr[title]";

If in themes, the SearchByMetadata plugin might do what you need. You’d configure it to search on titles.

I appreciate this but it’s not what I want – this plugin converts fields into searches for records that have the same field with the same value. But I want the system to find ITEMS whose title matches the value of the AUTHOR field, you see what I mean?

I can manually create a link that searches (this is what the plugin you sent me does) like this:


but this leads the user to a search results page but I want to link to link them to the Author Item page (i.e., do the search programmatically in the theme).

You probably will want to use the get_records function, then.

$items = get_records('Item', array('advanced' =>
            'element_id' => 50,
            'type' => 'is exactly',
            'terms' => $authorName

You can give get_items basically the same parameters you give in the URL for searching, and it will return an array of matches. You could pull the first result (if there are any) out of this array and then you could link directly to it with link_to:

echo link_to($item, null, 'text of link');