I have a very complex situation in which I need to pull out one entry from a Super Search results loop and re-inject it in a different location on the page. I'm planning on using NSM Transplant for that part and some early tests indicate it will work fine.
The tricky part is writing a conditional inside the Super Search loop that will identify the correct entry to pull out via Transplant. I want to only transplant the entry if the category or categories searched include the Primary Category of that entry - which in my case is a location.
So in plain english this is the conditional I want:
If {this_entry's_primary_category} is contained in {super_search_category} then do something with Transplant, otherwise, leave it alone
I'm using CE String so my first thought was to check if the {super_search_category} string contained the primary category URL title with strpos, something like this (this is inside exp:super_search:results
):
{if "{exp:ce_str:ing strpos='{exp:primary_category entry_id='{entry_id}'}{primary_category_url_title}{/exp:primary_category}'}{super_search_category}{/exp:ce_str:ing}" != "-1"}
This always returns false - even on the entry where the primary category should be found within super search category. I think it's because {super_search_category}
only works outside the exp:super_search:results
tag. Is this correct?
Any suggestions for the easiest way to test to see if an entry's Primary Category is included in category or categories searched on a Super Search results page?
Edit to add some recent code examples
This is on a Super Search results page:
{exp:stash:set name="ss-cats" parse_tags="yes" parse_depth="2"}{super_search_category}{/exp:stash:set}
{exp:super_search:results
redirect_post="yes"
channel="directory"
status="Open|Featured"
performance="off"
category_indicator="category_url_title"
search-words-within-words="yes"
inclusive_categories="yes"
orderby="vendor-group+desc+vip+desc+rating_field-rating+desc+title+asc"
search_in="title|vendor-person|about|extended|address|awards"
inclusive_keywords="no"
where="all"
limit="50"
paginate="bottom"
}
{exp:stash:get name="ss-cats"}
<!-- lots of stuff here removed for simplicity -->
{/exp:super_search:results}
At the moment, I'm not even getting this simple stash set/get to work so I can read the value of {super_search_category} inside the results loop.
Edit for progress below:
{super_search_category}
returns category URL titles if used outside results loop.
If you used INSIDE results loop it does nothing (tag is not parsed at all).
If I use Stash to save the tag output from outside the results loop it works to some extent:
{exp:stash:set name="ss-cats" parse_tags="yes" parse_depth="1"}{super_search_category}{/exp:stash:set}
Stash get SS cats outside results: {exp:stash:get name="ss-cats"}
{exp:super_search:results
redirect_post="yes"
channel="directory"
status="Open|Featured"
performance="off"
category_indicator="category_url_title"
search-words-within-words="yes"
inclusive_categories="yes"
orderby="vendor-group+desc+vip+desc+rating_field-rating+desc+title+asc"
search_in="title|vendor-person|about|extended|address|awards"
inclusive_keywords="no"
where="all"
limit="50"
paginate="bottom"
}
Stash get SS cats inside results: {exp:stash:get name="ss-cats"}
{/exp:super_search:results}
In this case the stash:get outside results works fine, but the stash:get inside results returns something different (a completely different category name - which isn't even the Super Search category!).
So I fail to see how I can read {super_search_category} from within the results in order to use it in a conditional.