get_items by tag 2.1

$items = get_items(array('tags' => 'foo,bar'), 20);

How do I do this in Omeka 2.1?

The separate get_* functions are consolidated into get_records in Omeka 2.x.

So it would be something like:

$items = get_items('item', array('tags'=>'foo'), 20);

Sorry. that should have been

$items = get_records('item', array('tags'=>'foo'), 20);

Thats what I tried actually.. I want to get all items with the tag "foo" into an array $items (then loop through them) this code:

<?php $items = get_records('item', array('tags'=>'foo'), 20); ?>

yields this error:

Warning: array_keys() expects parameter 1 to be array, boolean given in /home/nyarcorg/public_html/omeka/application/libraries/Omeka/Db/Table.php on line 132

Warning: Invalid argument supplied for foreach() in /home/nyarcorg/public_html/omeka/application/libraries/Omeka/Db/Table.php on line 358

Fatal error: Class 'item' not found in /home/nyarcorg/public_html/omeka/application/libraries/Omeka/Db/Table.php on line 625

Hmm...seems odd that it can't find the class 'item'. The function should be trying to inflect it into 'Item', so maybe try using 'Item' instead of 'item'.

tried Item-- page wouldn't even parse.

n.b. this is a simple pages page. (shouldnt matter?)

When I tried with Item in a simple page, it seemed to work. Maybe there's some other detail that's causing the page not to parse? Is it the same error with 'Item' that you reported above?

here's the block of code. bad syntax?

<?php $items = get_records('Item', array('tags'=>'Beethoven'), 20); ?>

<div id="browse" class="flexslider">
<ul class="slides">
<?php foreach (loop('items') as $item): ?>

 <?php if (metadata('item', 'has thumbnail')): ?>

<li><?php echo link_to_item(item_image('square_thumbnail')); ?></li>
<?php endif; ?>

<?php endforeach; ?>

</div>

with "Item" error is 404 page not found

Did you test and display an array of items on Simple Pages?

I guess Im confused about how to loop through the $items array after that ...

error I get with this code is 404-page not found

Here's what I have that's working on my install, at least:

<?php $items = get_records('Item', array('tags'=>'foo'), 20); 

set_loop_records('items', $items);
?>

<div id="browse" class="flexslider">
<ul class="slides">
<?php foreach (loop('items') as $item): ?>

 <?php if (metadata('items', 'has thumbnail')): ?>

<li><?php echo link_to_item(item_image('square_thumbnail')); ?></li>
<?php endif; ?>

<?php endforeach; ?>
</ul>
</div>

I closed the <ul>, and the big change to make the loop work is adding the set_loop_records() line. That's the ingredient to make the loop happen.

I'm not sure about the 404 error, though. Something at least should load then display the error. Often that happens when the page is not public, and you are not logged in.

brilliant!

thanks so much

I copied this exact code into my Simple Page, but I'm getting Parse error: syntax error, unexpected '$items' (T_VARIABLE) in /omeka/www/data/plugins/SimplePages/views/public/page/show.php(14) : eval()'d code on line 1

Do I need to have a line defining what $items is before this code?