Thanks for the reply; it helped point me in the right direction. I tried:
if (isset($_GET['advanced'])) {
$getItemsParams['advanced_search'] = $_GET['advanced'];
}
When I initially did this it was still not working. I had added a conditional statement to get the collection info to the $getItemsParams array. When I did a print_r($getItemsParams) it included something like [search] => [collection]=> in the array, and didn’t work when using an advanced search on a specific field. I noticed if I included a collection limiter in my advanced search, then it would work and successfully keep me within my search results when clicking next and previous. Then I removed the conditional statement for the collection and search fields and tried it with just the code at the beginning of the post. Now it worked if I ran an advanced search with no collection selected, and didn’t work if the collection was selected. I noticed after running an advanced search it had terms, collection, and tags in the url. At this point I figured I just needed to prevent keys from getting set to empty values when populating the $getItemsParams array.
So this is what I have, and it works. Basically in the collection, tags, and advanced search spots, there's an extra conditional statement to determine if these are empty. If you have any more concise ways to write this, I’d appreciate it:
function custom_next_previous()
{
$getItemsParams= array();
if (isset($_GET['search'])) {
$getItemsParams['search'] = $_GET['search'];
}
if (isset($_GET['collection'])) {
$collection=$_GET['collection'];
if(strlen($collection)>0){$getItemsParams['collection'] = $_GET['collection'];}
}
if (isset($_GET['tags'])){
$tags=$_GET['tags'];
if(strlen($tags)>0){$getItemsParams['tags']=$_GET['tags'];}
}
if (isset($_GET['advanced'])) {
$advancedsearch=$_GET['advanced'];
if (isset($advancedsearch['element-id'])){
$getItemsParams['advanced_search'] = $_GET['advanced'];
}
}
if (isset($_GET['sort_field'])) {
$getItemsParams['sort_field'] = $_GET['sort_field'];
}
if (isset($_GET['sort_dir'])) {
$getItemsParams['sort_dir'] = $_GET['sort_dir'];
}
if ($getItemsParams){
$current = item('id');
$list=get_items($getItemsParams,total_results());
foreach ($list as &$value) {
$itemIds[] = $value->id;
}
$key = array_search($current, $itemIds);
if ($key > 0) {
$previousItem = $list[$key - 1];
$previousUrl = item_uri('show', $previousItem) . '?' . $_SERVER['QUERY_STRING'];
echo '<li><a href="' . $previousUrl . '">Previous Item</a></li>';
}
if ($key < count($list) - 1) {
$nextItem = $list[$key + 1];
$nextUrl = item_uri('show', $nextItem) . '?' . $_SERVER['QUERY_STRING'];
echo '<li class="next"><a href="' . $nextUrl . '">Next Item</a></li>';
}
}
else {
echo '<li>'.link_to_previous_item('Previous Item').'</li>';
echo '<li class="next">'.link_to_next_item('Next Item').'</li>';
}
}