ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Use a variable as a search parameter in a channel:entries tag?

May 16, 2011 11:36am

Subscribe [3]
  • #1 / May 16, 2011 11:36am

    rubberglover

    11 posts

    Hi all…

    I’m trying to use a custom field from a single entry as a search parameter in a separate channel entries tag. Is this possible? I’m currently using MX_Jumper plugin to store the custom field as a reusable variable. It works when echoed out elsewhere in the template but I can’t reference this variable from within the channel entries tag definition. Here’s some code…

    The following chunk of code saves the data from a custom field called ‘media_type’ to an mx_jumper variable called ‘current_type’

    {exp:channel:entries channel="media_review" limit="1" dynamic="yes"}
                
        {exp:mx_jumper:put name=“current_type”}{media_type}{/exp:mx_jumper:put} 
    
    {/exp:channel:entries}
    
    MX Jumper variable = {exp:mx_jumper:out name=“current_type”}

    Notice I can now echo out the mx_jumper variable outside of the channel entries tag… I want to reference this variable as a search parameter in another channel entries tag later on the page. Think of it as showing related articles. I’ve tried accessing this variable using the code below, but it doesn’t work:

    {exp:channel:entries channel="media_review" dynamic="no" search:media_type="{exp:mx_jumper:out name='current_type'}"}
    // output data here…
    {/exp:channel:entries}

    I’m assuming the above doesn’t work because I can’t call a plugin tag from within a channel entries tag?

    I know I could probably use categories to solve this but in this instance i want to use a drop down menu, as I can make it a required field, and restrict the admin to only selecting one option. Anyone know a solution to this? Will I just have to use PHP variables? If so how do I go about doing this?

  • #2 / May 16, 2011 9:22pm

    Sue Crocker

    26054 posts

    Hi, rubberglover. Since this involves a third party plugin, have you mentioned this to the author? I’m not familiar with that plugin.

  • #3 / May 17, 2011 7:39am

    rubberglover

    11 posts

    Happy to try and achieve this functionality without a plugin… I want to use a variable from a dynamic channel entries tag call in a non-dynamic tag call. Eg, if I’m viewing an article, I want to take a variable from that article and use it to tailor the results I get from a separate non-dynamic channel entries call. Has anyone else managed to do this?

  • #4 / May 18, 2011 3:09am

    John Henry Donovan

    12339 posts

    rubberglover,

    You could use an embed.

    In your first template

    {exp:channel:entries channel="media_review" limit="1" dynamic="yes"}
                
        {embed="_includes/related-embed" mediatype="{media_type}"
    
    {/exp:channel:entries}

    Then in your embed template

    {exp:channel:entries channel="media_review" dynamic="no" search:media_type="{embed:mediatype}"}
    // output data here…
    {/exp:channel:entries}
  • #5 / May 19, 2011 10:51am

    rubberglover

    11 posts

    Great idea… thanks John. This method will probably work with an mx_jumper variable too which will allow me call the embed from outside the channel entries tag. Will try it now and post if works… thanks!

  • #6 / May 19, 2011 11:17am

    rubberglover

    11 posts

    All sorted! Couldn’t get it to work with MX_Jumper; guess there’s a problem in the order in which templates / embeds / plugins are processed by EE. No matter though - tweaked the markup so that I could post the related entries via an embed from within the channel entries tags as per your recommendation, and it worked a charm.

    In case anyone else wants to do this, I also added another embed variable to make the ‘related articles’ embed skip showing the currently viewed post…

    {exp:channel:entries channel="media_review" limit="1" dynamic="yes"}
                
        {embed="_includes/related-embed" mediatype="{media_type}" current_post="{entry_id}"}
    
    {/exp:channel:entries}

    Then in the embed, added an entry_id =“not ” to the channel entries call…

    {exp:channel:entries channel="media_review" dynamic="no" search:media_type="{embed:mediatype}" entry_id="not {embed:current_post}"}
    // output data here…
    {/exp:channel:entries}

    Many thanks again for the tip on the embed!

  • #7 / May 19, 2011 11:48am

    Sue Crocker

    26054 posts

    Glad John was able to help. Don’t hesitate to post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases