Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Solved] Get list of unread private messages


  • prowseed
    Participant

    @prowseed

    Hello,
    I’d like to know if there is a clean way to display the user only unread messages. I want to display on a front page unread messages’ excerpts that will lead to the particular message.
    There is a ‘bp_message_thread_has_unread()’ in the loop that gives me nothing, because I want to display 5 last messages that has status of unread.
    Any help or hints would be great.
    Thanks

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

  • shanebp
    Moderator

    @shanebp

    Did you look at the codex?
    https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-private-messages-loop-bp_has_message_threads/

    Try this to start your loop
    `

    `

    I’m not sure if ‘type=unread’ is valid.

    bp_message_thread_has_unread() returns true or false
    So you can use it in your loop to decide whether to proceed.


    prowseed
    Participant

    @prowseed

    And did YOU look at the codex? :)
    Ofcourse, it was the first thing I did when I discovered the problem. I’ve been heavy googling for one hour after I made this question. At the codex there is info that the olny accepted parameters are:
    {user_id, box, per_page, max}. Perhaps “box=notices” would be some point of interest (can’t check now as I’m away from working env) but obviusly there’s nothing like type ;)

    And about: bp_message_thread_has_unread()
    I don’t want to check if the message I get is unread or not, but I need to make this filter on the level of query ( not display ), so I am getting only unread messages, not ‘n’ number of messages from which I am displaying only those that are unread because either way I will not display all of them or I will have to query very big amount.

    I see the great power of BuddyPress, but I’m pretty new in this system (it’s my second day :) ) and I’m jumping through files and functions looking for some clue. I could optionaly make it dirty hardcode, but then everyone in my team would push me to the pit of inferno ;)

    //EDIT
    Anyway: Thanks for interest :)


    shanebp
    Moderator

    @shanebp

    See bp_has_message_threads() for type param. It defaults to ‘all’.

    You don’t need to dirty hardcode anything – you just need (maybe) to write a custom query and call it from a theme file.
    read/unread is stored in wp_bp_messages_recipients

    Good luck


    prowseed
    Participant

    @prowseed

    @shanebp, you are awesome : )
    I just jumped into my ftp, located the function bp_has_message_threads() and trully there is a type param. And… the code you posted on top works like a dream : )
    Thanks again.


    Hope
    Participant

    @amalsh

    Interesting!

    I want to add dropdown list to choose between showing all or unread messages, how could this be applied? I added the following code but nothing happens:
    `

    `
    Thanks in advance
    Hope


    Hope
    Participant

    @amalsh

    Apparently there’s no way to copy the code here :S Anyway do you know how to do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Solved] Get list of unread private messages’ is closed to new replies.
Skip to toolbar