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.

different behavior for author_id and username parameters in channel entries tag?

October 05, 2011 5:48am

Subscribe [2]
  • #1 / Oct 05, 2011 5:48am

    earache6

    1 posts

    I’ve noticed something unexpected in the Channel Entries tag, and haven’t found any mention of it in the docs or on the web in general. I expected the author_id and username parameters to be essentially interchangeable, but they seem to behave differently when there are no matches.

    For example, let’s assume a member with the username “bob”, whose member id is 2.
    This tag:

    {exp:channel:entries channel="gallery" author_id="2"}

    and this:

    {exp:channel:entries channel="gallery" username="bob"}


    should produce the same results, right?

    If Bob doesn’t have any entries in this channel, the first tag (using the author_id parameter) ouputs nothing, as expected. But the second tag (with the username) outputs the most recent entry in the channel, regardless of author.

    Since I’m using usernames like category urls for this site, it would be great to be able to rely on the channel entries tag to limit the entries by username even if there is no match—I don’t want to show a different member’s gallery on Bob’s page. Of course I can use a SQL query to get the member id from the username and feed that to channel:entries, but that’s kind of a kludge. I feel like I must be missing something obvious, but I’ve done a lot of searching and turned up nothing.

  • #2 / Oct 06, 2011 8:09am

    Sue Crocker

    26054 posts

    Welcome to the ExpressionEngine forums, earache6.

    Quick question before I attempt to test this - Can you tell us which version/build of EE2.x you’re using? See EEWiki:// HowTo Determine My EE Version

    Have you tried using if_no_results ?

    http://ellislab.com/expressionengine/user-guide/modules/channel/conditional_variables.html#cond_if_no_results

  • #3 / Oct 07, 2011 2:59am

    earache6

    1 posts

    Hi Sue,
    I’m using 2.2.2 - Build: date 20110801

    I wasn’t using no_results at the time, but added it soon after I started this thread. That didn’t help, most likely because it may well have been a PEBKAC situation anyway. I think I must have been declaring an empty username, probably by trying to use preload_replace like a variable. At any rate, it works as expected now. Another issue has cropped up in its place, but it’s different enough to be a separate thread.

    thanks,
    Eric

  • #4 / Oct 07, 2011 7:31am

    Sue Crocker

    26054 posts

    Glad to hear it, Eric. Feel free to start a new thread if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases