We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using a custom field to define search results.

Development and Programming

CADAUDIO's avatar
CADAUDIO
13 posts
9 years ago
CADAUDIO's avatar CADAUDIO

I’m sure there is an easy solution to this, but I can’t seem to locate one.

I have a set of products in the products channel, I want to use search: in a side bar and a custom field to define what those search results return.

This works:

{exp:channel:entries channel="products" dynamic="off" orderby="date"  search:product_sub_title="GXL" sort="desc" limit="2"}

This doesn’t:

{exp:channel:entries channel="products" dynamic="off" orderby="date"  search:product_sub_title="{products_used}" sort="desc" limit="2"}

Is it possible to use a text input from a channel field from a specific entry to define what another channel tag displays?

Thanks Much!

       
James Mathias's avatar
James Mathias
225 posts
9 years ago
James Mathias's avatar James Mathias

Hi,

This might be what you are looking for Dynamic Parameters if I understand the problem correctly.

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
9 years ago
Ingmar Greil's avatar Ingmar Greil

Looks like you are running into parse order issues here. For this to work you’d have to nest exp:channel:entries tags, which is generally not recommended. Have you tried an embedded template?

{exp:channel:entries ... } 
{embed=group/template my_product_sub_title="{product_sub_title}"}
 ...
{/exp:channel:entries}

And then, in group/template you’d use something like

{exp:channel:entries search:product_sub_title="{embed:my_product_subtitle}"}

Makes sense?

ETA: Or, what James says 😊

       
CADAUDIO's avatar
CADAUDIO
13 posts
9 years ago
CADAUDIO's avatar CADAUDIO

Basically it’s like this.

I have a page of artists pulling from the “artists” channel.

Each one of these artists use specific products from the “products” channel.

So, within the artist’s channel -> publish -> artists I want to use a custom field to define the search for the products used in the side bar.

I’ve been thinking about using a cookie as a var, then using the var in search:product_sub_title=”“

Set var inside channel and use var to create cookie:

$(document).ready(function (){ 
//define var from channel field products used
var products_used = "{products_used}";
});

$(document).ready(function () {
//set cookie for var set above 
Cookies.set('exp_products', products_used  );
});

Then retrieve cookie and us the var inside search:product_sub_title=”products_used”

But no luck. I guess there’s no way to use a js var inside an EE tag?

Edit: and oh, I have this $conf[‘protect_javascript’] = ‘n’; defined in my config file.

Setting the cookie using the channel field is working. It’s using the var to change the search keyword that’s not.

I suppose there’s a better logic to make this happen…

       
CADAUDIO's avatar
CADAUDIO
13 posts
9 years ago
CADAUDIO's avatar CADAUDIO

Got it! I had to turn PHP Parsing Stage to input. duh…

So basically, to summarize in case anyone else needs to do the same.

I set a cooking using https://github.com/js-cookie/js-cookie

I created a var out of my Channel Field within my Channel tag:

script
//set var on channel field "products used"
var products_used = "{products_used}";
/script

Set Cookie with var:

script
$(document).ready(function () {
//set cookie using var set above 
Cookies.set('exp_products', products_used  );
});
/script

Then just echoed the cookie into my sidebar channel:

{exp:channel:entries channel="products"  
dynamic="off" orderby="date"  
sort="desc" limit="2" 
search:product_sub_title="<?php echo " ".$_COOKIE['exp_products']; ?>"}

Works like a charm.

Except you have to use ajax to load the sidebar, otherwise the cookie doesn’t read on first load.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.