We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered Filter by Author

    • 40088
    • 708 Posts
    Some progress ... there is now a listing of posts, but it's returning all posts by all authors, it's not being filtered by a specific author.

    Here's what I'm using. Can anyone spot the problem?

    Author link:
    <a href="[[~27]]?author=[[*createdby:userinfo=`fullname`]]">[[*createdby:userinfo=`fullname`]]</a>

    Author landing page:
    [[!getResources? 
        &parents=`0` 
        &where=`{"createdby:=":[[!+modx.user.id]]}` 
        &tpl=`Search Results`
    ]]
    [[+results]]
    
    [[!+page.nav:notempty=`
    <div class="paging">  
    <ul class="pageList">  
      [[!+page.nav]]  
    </ul>  
    </div>
    `]]
    [ed. note: todd.b last edited this post 11 years, 10 months ago.]
      Todd
      • 3749
      • 24,544 Posts
      Try this (without the exclamation point):

      [[+modx.user.id]]

        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
        • 40088
        • 708 Posts
        [Throws hands up] Well, I surrender.

        It still doesn't filter by author, every post from every author is listed.

        Thanks for trying, Bob. [ed. note: todd.b last edited this post 11 years, 10 months ago.]
          Todd
        • discuss.answer
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          What you're doing with this:

          [[!getResources? 
              &parents=`0` 
              &where=`{"createdby:=":[[!+modx.user.id]]}` 
              &tpl=`Search Results`
          ]]

          is filtering based on the currently logged in user, not what you passed in the url. Also you're filtering on createdby here, but passing publishedby in the url - those could be different people, so could lead to weird results.

          I would go back to your link generation and change it to this:
          <a href="[[~27? &author=`[[*publishedby]]`">[[*publishedby:userinfo=`fullname`]]</a>


          That will make the urls a bit uglier as it uses the ID, but it makes the filtering easier.

          Next, install getUrlParam from the Package Manager. This is a snippet that will let you easily access GET params, so you can grab the passed ID. Getting the author id from the url would look something like this.
          [[!getUrlParam? &name=`author` &int=`1`]]


          Combine that with your getResources call, replaceing createdby with publishedby for consistency, and you get this:

          [[!getResources? 
              &parents=`0` 
              &where=`{"publishedby:=": [[!getUrlParam? &name=`author` &int=`1`]] }` 
              &tpl=`Search Results`
          ]]


          And you should be good to go.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 40088
            • 708 Posts
            Thank you for the explanation, Mark.

            It appears posts created/published by the admin (sudo) are being filtered correctly, however posts created/published by member users are not being recognized, i.e., the filter returns 0 results for them.
              Todd
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              Whoops, missed a few brackets (in the href attribute):

              <a href="[[~27? &author=`[[*publishedby]]`]]">[[*publishedby:userinfo=`fullname`]]</a>


              created/published are two different actions so it's important to distinguish those.. createdby indicates who first created the resource, while publishedby indicates who hit the publish button. Maybe only the admin user has been hitting the publish button?

              You can also set a &debug=`1` property on the getResources call by the way. That will send the SQL query for fetching the resources to the error log, so you can see if it is doing what you expect it to do.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 40088
                • 708 Posts
                Thank you very much, Mark. It now seems to be properly filtering all users.

                Finally, I'm trying to pass both the user's fullname and the number of results to the landing page, e.g.,

                “[count] articles found by [fullname]”

                I tried using [[+count]] and [[*createdby:userinfo=`fullname`]] but the count doesn't work and name defaults to the admin even when filtering by a different (non-admin) user. I tried debugging but I can't see anything amiss. [ed. note: todd.b last edited this post 11 years, 10 months ago.]
                  Todd