2

I'm building a custom plugin tag pair which returns channel entries, following the excellent answer to this question. Almost everything seems to be working: I set the TMPL->tagparams array to my custom params, instantiate a new Channel(), and return its entries.

I'm searching a "classes" channel where entries have a "weekday" custom field with values like "Monday", "Tuesday", etc. In the case, I want to return the first 5 classes on Mondays.

$this->EE->TMPL->tagparams = array('channel'        => 'classes',
                                   'limit'          => '5',
                                   'search:weekday' => '=Monday');

if ( ! class_exists('Channel')) {
  require_once(APPPATH.'modules/channel/mod.channel.php');
}
$channel = new Channel();

return $channel->entries();

EE seems to be ignoring the search:weekday param. It's returning the right channel and enforcing the limit, but it's returning all results, not just results with "Monday" for their "weekday" custom field. How can I use search params in a plugin like this?

Update: to provide more use-case info and clarify that I'm searching a custom field with the search param.

2

The search parameters belong in a different property of the Template object: ee()->TMPL->search_fields

So use something like this:

ee()->TMPL->search_fields['weekday'] = '=Monday';
| improve this answer | |
  • That did the trick. Thanks, Low! – Steve Grossi Oct 30 '14 at 16:02
0

Ah - this is because the search parameter will only search custom fields - it won't search the title (or any other field which resides in exp_channel_titles as opposed to exp_channel_data).

What you'll have to do if you want to support this in your plugin is check to see if that parameter was passed, and if so, do a separate database query for all titles including that phrase. Then, concatenate the resulting Entry IDs into a pipe-delimited string, and feed that back as the entry_id parameter on ee()->TMPL->tagparams.

| improve this answer | |
  • Thanks, I was hoping this would solve it, but it doesn't seem to work searching custom fields either. I've updated the question with this new, more correct use-case. – Steve Grossi Oct 30 '14 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.