We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    In a member's account area I'm able to show a total count of all published articles for that particular signed-in member. For example:

    getResources
    [[!getPage?
        &elementClass=`modSnippet`
        &element=`getResources`
        &parents=`2,3,4`
        &resources=`-1`
        &where=`{"createdby:=":[[!+modx.user.id]]}`
        &showHidden=`1`
        &hideContainers=`1`
        &toPlaceholder=`myArticles`
        &totalVar=`total`
    ]]

    Placeholder
    [[!+myArticles:notempty=`<span class="messageCount">[[+total]]</span>`]]


    Works great. In addition to this I would also like to show the number of unpublished articles (drafts) for that member.

    I've had limited success so far. I started by using,
    [[+published:is=`0`:then=`Drafts [[getResources? &parents=`2,3,4` &showUnpublished=`1` &totalVar=`totalDrafts`]] [[+totalDrafts]]`:else=``]]

    Placeholder
    [[+totalDrafts]]

    But that returns too many results, none of which are unpublished resources for that particular user.

    Ideas?

    This question has been answered by sottwell. See the first response.

    [ed. note: todd.b last edited this post 8 years, 8 months ago.]
      Todd
    • discuss.answer
      I think you could use basically the same snippet call as for published articles, only add to the WHERE clause:
          &where=`{"createdby:=":[[!+modx.user.id]], "AND:published:=":0}`

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 40088
        • 708 Posts
        Doesn't seem to work for me. The 'published' count goes missing and still no unpublished count.
          Todd
        • Two snippet calls, the first one for published, and the second one with the extra bit in the &where property as well as the showUnpublished property set to 1?
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            Since you don't plan to display the unpublished ones, you should be able to get a quick count with this in a custom snippet:

            $userId = $modx->user->get('id');
            
            $c = $modx->newQuery('modResource');
            $c->where(array(
                'createdby' => $userId,
                'published' => false,
            ));
            
            return $mod->getCount('modResource', $c);
            
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting