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.

search:custom_field="{member_id}" not working

May 08, 2009 4:45pm

Subscribe [2]
  • #1 / May 08, 2009 4:45pm

    Tony Gravett

    34 posts

    I am unable to get the search:custom_field functionality to work, based on searching a custom field (named primary_account) using a member’s id as the search term:

    {exp:weblog:entries weblog="sub-accts" search:primary_account="{member_id}" status="open" disable="categories|trackbacks|pagination" dynamic="off"}

    I have tried using {logged_in_member_id} instead, and assigning the member ID using a declared variable such as

    {assign_variable:curr_member_id="{logged_in_member_id}"}

    but nothing has worked. The rest of the code works fine, and when I “hard-wire” a member ID into the code, it works.

    Does anybody have any suggestions for how to get the {member_id} variable to work in this context ... or another way of implementing a search like this?

  • #2 / May 08, 2009 5:44pm

    Mark Bowen

    12637 posts

    You’re most likely running into a parse order issue here.

    You will probably need to turn on PHP parsing for the template and then do this sort of thing :

    {exp:weblog:entries weblog="sub-accts" search:primary_account="<?php global $SESS; echo $SESS->userdata['member_id']; ?>"}

    Pretty sure that should do it for you.

    Don’t forget to turn on PHP parsing for the template you have this code in though 😉

    Best wishes,

    Mark

  • #3 / May 08, 2009 6:55pm

    Tony Gravett

    34 posts

    Many thanks, Mark ... that did the trick!

  • #4 / May 08, 2009 6:56pm

    Mark Bowen

    12637 posts

    No problem, glad that got it sorted for you 😉

    Hope it all goes well for you.

    Best wishes,

    Mark

  • #5 / Jun 14, 2009 6:37pm

    mayest

    293 posts

    @Mark, once again, I find that you’ve posted a solution that I needed. One thing about this solution is that it only works for me when I set the PHP Parsing Stage to Input. Is that correct, or do I have something else wrong in my template?

  • #6 / Jun 14, 2009 6:58pm

    Mark Bowen

    12637 posts

    @Mark, once again, I find that you’ve posted a solution that I needed.

    I try my best 😉

    Glad it helped you out.

    One thing about this solution is that it only works for me when I set the PHP Parsing Stage to Input. Is that correct, or do I have something else wrong in my template?

    No that’s correct you will need to have it set to Input stage for this to work. Input stage simply means that the PHP will get parsed before any ExpressionEngine tags allowing you to do what we are doing here.

    If you were to set it to Output stage then it means that you can use PHP to alter the template which is rendered out to the page.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #7 / Jun 14, 2009 11:14pm

    mayest

    293 posts

    Mark,

    Thanks. Much appreciated. Of course, I had some other PHP in that template that broke when I set the parsing to input. If its not one thing, it is another. 😊 I was able to fix that by putting that bit into an embedded template and sending it the custom field that it was using. All is good now.

  • #8 / Jun 15, 2009 6:12am

    Mark Bowen

    12637 posts

    Excellent, glad everything’s working for you.

    Hope everything else goes well.

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases