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.

Using {group_id} variable in a channels search parameter doen't work

February 01, 2012 12:02pm

Subscribe [2]
  • #1 / Feb 01, 2012 12:02pm

    adrake9

    57 posts

    Hopefully someone can shed some light on this. I’m trying to pass the current group_id from the logged in user into the search parameter of the exp:channel:entries tag. But it is not working.

    This works:

    {exp:channel:entries search:custom_field="1" }
        channel content
    {/exp:channel:entries}

    This doesn’t:

    {exp:channel:entries search:custom_field="{group_id}" }
        channel content
    {/exp:channel:entries}

    Any insight on why this does not work would be greatly appreciated.

    -a

  • #2 / Feb 01, 2012 12:11pm

    bottleboot

    54 posts

    weird that should work.
    Does

    {group_id}

    on itself do anything?
    Is the user logged in?

  • #3 / Feb 01, 2012 1:36pm

    adrake9

    57 posts

    I’m wondering if it has something to do with being a number or a character. Maybe the custom_field needs to be configured differently. {group_id} does work in all other instances, both outside the channel entry tags and inside the entry tags.

  • #4 / Feb 01, 2012 8:45pm

    adrake9

    57 posts

    Ok. solved. Template needs to be set to parse PHP on input. Member fields are parsed way later in the parse order so the variables won’t get generated until eveything else is done. Which means they don’t get to be used as parameters in your channel tags. So in order to make it work you have to do a little php…

    <?php
    $group_id = $this->EE->session->userdata['group_id'];
    ?>

    and then call it using php in the template

    search:channel_field="<?php echo $group_id; ?>"

    Hope this helps….

  • #5 / Feb 02, 2012 5:11pm

    Dan Decker

    7338 posts

    Hey adrake9,

    What you were running into here is EE’s parse order. {group_id} is a late-parsed global variable, it isn’t read until after the channel entries tag has processed. It looks as though you have found a workaround using PHP.

    If you need anything else, just let us know.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases