0

I am trying to run a conditional which displays a "can't post" message if the member of a group_id 1 had previously posted 2 entries in a channel. Otherwise, it displays a channel form to post an entry.

If the member belongs to group_id 2, he/she can't post more than 5 entries. Less than 5 entries, displays the channel form.

{if logged_in}
{exp:member:custom_profile_data member_id="{logged_in_member_id}"}

{exp:channel:entries
    channel="news"
    author_id="CURRENT_USER"
    dynamic="no"
    start_on="-1 months"
    stop_before="now"
    disable="pagination"
    status="not closed"
    parse="inward"
}
{if logged_in_group_id == 1}
    {if absolute_count < 2 }
{if:else}
    {if absolute_count < 5 }
{/if}
        Display the channel form
    {if:else}
        Throw an error message!
    {/if}

{/exp:channel:entries}
{/exp:member:custom_profile_data}
{/if}

Any pointers?

1

Looks like your conditional logic is awry. Try something like:

{if logged_in}
{exp:member:custom_profile_data member_id="{logged_in_member_id}"}

    {exp:channel:entries
        channel="news"
        author_id="CURRENT_USER"
        dynamic="no"
        start_on="-1 months"
        stop_before="now"
        disable="pagination"
        status="not closed"
        parse="inward"
    }
    {if 
        (logged_in_group_id == 1 && absolute_count < 2) ||
        (logged_in_group_id == 2 && absolute_count < 5) ||
        no_results
    }
            Display the channel form
    {if:else}
            Throw an error message!
    {/if}

    {/exp:channel:entries}
    {/exp:member:custom_profile_data}
    {/if}

HTH

| improve this answer | |
  • 1
    The absolute count was creating a problem. Had to use stash and set a variable with scope=local and then call it instead of absolute_count. It worked dandy! – Noor M Nov 23 '16 at 20:37
  • There seems to be a problem if there are no results. Need to display the form, if the member hasn't posted any entry. – Noor M Nov 25 '16 at 1:49
  • You just need to add a conditional to test for that - EE sets a variable called no_results if a channel:entries call produces nothing. I've amended the example - – JCOGS Design Nov 25 '16 at 9:41
  • The {if no_results} {/if} conditional outputs raw data of anything which is enclosed in it. A redirect did not help. However, an embed tag inside it, did help. {if no_results}{embed='forms/_post_news'}{/if}, where _post_news is the form template. – Noor M Nov 25 '16 at 11:39
  • OK - glad you got it sorted :) – JCOGS Design Nov 25 '16 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.