• Resolved Mosche

    (@mosche)


    Dear Support,

    I’m trying to filter an output of a custom post type, where the output is filtered based on the current user’s display name.
    [loop type=custom-post-type field=custom-field value=’user-name’]
    [field custom-field]
    [field custom-field1]
    [field custom-field2]
    [field custom-field3]
    [/loop]

    The custom-field is the same value as the user’s display name.
    How can I dynamically input the user display name as the value to be filtered.
    Or is there a different way I could filter custom posts based on the user viewing the page. Please advise.

    Regards,

    Mosche

Viewing 2 replies - 1 through 2 (of 2 total)
  • Peter Berger

    (@peterpolow)

    Hi,

    I’m not sure I’m following you…

    Do you want to display the posts of the current user? Then you can user this code…

    [loop type=custom-post-type author=this]
    	[field title]
    	[field custom-field]
    	[field custom-field1]
    	[field custom-field2]
    	[field custom-field3]
    [/loop]

    Or is the name of the user in the custom field another user then the author of the post?

    This code will display the post where the value in the custom field is equal to the display name (selected in the combo box of the user profile) of the user who is logged in.

    [pass user_field=fullname]
    [loop type=custom-post-type field=name-of-the-field value='{USER_FIELD}']
    	[field title]
    	[field custom-field]
    	[field custom-field1]
    	[field custom-field2]
    	[field custom-field3]
    [/loop] 
    [/pass]

    Keep in mind that the user can change his own display name, then it will not match the custom field anymore. Using the username for this is more solid…

    Peter

    By the way: I’m not “Support”, but just a all day user of this excellent plugin.

    Thread Starter Mosche

    (@mosche)

    Hi Peter,

    First of all, thank you! The second one is the one I was looking for and it works like a charm. And especially thanks for the speed of the support.
    Secondly, that is an excellent solution. I was not aware of the [pass] option.
    Thirdly, after your clarification I realized I meant the login name. The one that cannot be changed. The display name can be changed, so I’m better off using the login name instead. Since there is no guarantee that the user might accidentally change that.
    I used the code and substituted “fullname” with “name” in the first line and it works like a charm.
    Fourthly, this is an awesome plugin.

    Regards,

    Mosche

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Filter based on user’ is closed to new replies.