We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I am actually using pdoResources, but there's no section for it that I'm aware of.

    In my tpl I'm using [[+publishedon:strtotime:date=`%A, %B %e, %Y`]] for the date. This works great (with * instead of +) on the resource itself, however there is no output from pdoResources of date. So, noticing that no publish date is set at all (old articles, becoming resources just now) I set the pub_date as well. Voila! There it is, called up by [[+publishedon]] but with the new date coming from pub_date.

    I remember dealing with this before, but never did find a solution. I am going to rely on the site owner to move all their own content into the resources, and yes she can be sure to set the pub_date if I tell her to do so but for future articles I assume she'll just create them and the publishedon date will be set automatically. There will likely never be any reason to set a different date in pub_date, they will be published on save.

    According to the database, [[+createdon]] seemed like a possibility, as that is populated as well as publishedon regardless of manual input. But same as publishedon... there is no output.

    Searching just tells me that it appears that others are able to use publishedon as a placeholder in the tpl. I'm not stupid tired yet, so I'm able to say with certainty that it very clearly pulls out the pub_date with publishedon as the placeholder. The only result that shows a date is the one I added a pub_date to.

    Am I missing something basic here with the fields I ask for results from coming from another field entirely while using pdoResources?

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

      Frogabog- MODX Websites in Portland Oregon
      "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
      Having server issues? These guys have MODX Hosting perfected - SkyToaster
      • 42562
      • 1,145 Posts
      Trying to understand you:

      [[+createdon]] and [[+publishedon]], although they have a value in the database, do not output anything in your pdoResources call? but work in getResources!?
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • [[*publishedon]] works in the resource, it results in a different date than pub_date.
        [[+createdon]] does not work in the pdoResources call at all
        [[+publishedon]] pulls in [[pub_date]] in the pdoResources call

        getResources actually doesn't seem to work at all. That's odd... yes, it's installed.
        [[!getResources? &parents=`252,251` &tpl=`newsCollapse` &tplFirst=`newsCollapseFirst` &limit=`10` &includeContent=`1` &includeTVs=`1` &includeTVList=`newsImage,uniqueID,publishedon`  &tvPrefix=``]]


        The above includes publishedon in the includeTVList, but that was just an attempt at getting it to work. It pulls in from pub_date as seen below with or without that in the list.
        edit: yet it's now the wrong year.

        This works, but [[+createdon:strtotime:date=`%A, %B %e, %Y`]] pulls from pub_date
        [[!pdoResources? &parents=`252,251` &tpl=`newsCollapse` &tplFirst=`newsCollapseFirst` &limit=`10` &includeContent=`1` &includeTVs=`newsImage,uniqueID` &tvPrefix=``]]


        This also works (includeTVList shouldn't work afaik), but also pulls from pub_date
        [[!pdoResources? &parents=`252,251` &tpl=`newsCollapse` &tplFirst=`newsCollapseFirst` &limit=`10` &includeContent=`1` &includeTVs=`1` &includeTVList=`newsImage,uniqueID`  &tvPrefix=``]]


        Oh, look at that... the date is now
        Thursday, July 17, 5913

        I changed the date/time zone to America/LosAngeles in the settings today, because the time was wrong but I do think the year was 2015. I've refreshed, so now I'll never know.

        I'm going to change that pub_date and see what it shows me. [ed. note: frogabog last edited this post 8 years, 9 months ago.]
          Frogabog- MODX Websites in Portland Oregon
          "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
          Having server issues? These guys have MODX Hosting perfected - SkyToaster
          • 3749
          • 24,544 Posts
          That sounds crazy. The pub_date field is to set a future publication date and is emptied automatically when a resource is published. And the publishedon field is set automatically when an articles is saved as published or when the pub_date is reached.

          You're probably aware of all this, but for others who find this thread:

          http://bobsguides.com/published-on-publish-date-confusion.html

          http://bobsguides.com/blog.html/2014/03/17/how-auto-publish-works/

          I don't see how pdoResources could be reversing them because I'm sure it just uses get() with the field name you supply. The fact that * works and + doesn't suggests a caching issue, but if that were the case, neither field would work.

          You might try this as a custom snippet in the Tpl where you want the date. It will be much faster than using the output modifiers. I

          [[!getDate? &docId=[[+id]]]]


          /* getDate snippet */
          $docId = $modx->getOption('docId', $scriptProperties, '');
          
          $query = $modx->newQuery('modResource', array(
              'id' => $docId,
          ));
          $query->select('publishedon');
          $date = $modx->getValue($query->prepare());
           
          if ($date === false) {
              $output = 'Resource not found';
          } elseif (empty($date)) {
              $output = 'The publishedon field is empty';
          } else {
              $output =  strftime("%m, %d, %Y", $date); // Try this before changing to your preferred format
          }
          return $output;
          
          [ed. note: BobRay last edited this post 8 years, 9 months ago.]
            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
          • It is really odd.

            Now the pub_date isn't sticking. Was gone when I reloaded the resource. And it disappears when I reload, and nothing is output at all.

            The date was showing, and appeared right after I set something into the pub_date field. Stayed all evening, reload upon reload. But not now.

            I'm going to try your snippet Bob. Cross fingers!
              Frogabog- MODX Websites in Portland Oregon
              "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
              Having server issues? These guys have MODX Hosting perfected - SkyToaster
            • Well... that broke it. ??

              Parse error: syntax error, unexpected '}' in /home/columbia/public_html/core/cache/includes/elements/modsnippet/76.include.cache.php on line 15


              Made getDate snippet:

              <?php
              /* getDate snippet */
              $docId = $modx->getOption('docId', $scriptProperties, '');
               
              $query = $modx->newQuery('modResource', array(
                  'id' => $docId,
              ));
              $query->select('publishedon');
              $date = $modx->getValue($query->prepare());
                
              if ($date === false) {
                  $output = 'Resource not found';
              } elseif (empty($date)) {
                  $output == 'The publishedon field is empty'
              } else {
                  return strftime("%m, %d, %Y", $date); // Try this before changing to your preferred format
              }


              plopped this into the tpl:
              [[!getDate? &docId=[[+id]]]]
                Frogabog- MODX Websites in Portland Oregon
                "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                Having server issues? These guys have MODX Hosting perfected - SkyToaster
              • discuss.answer
                • 3749
                • 24,544 Posts
                My bad. There were several errors in the code (fixed above).
                  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
                • It appears this has to do with pdoResources. On a site where publishedon works fine, I changed the getPage/getResources call to pdoPage/pdoResources and the date disappeared. Changed it back, works again.

                    Frogabog- MODX Websites in Portland Oregon
                    "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                    Having server issues? These guys have MODX Hosting perfected - SkyToaster
                    • 3749
                    • 24,544 Posts
                    What happens if you leave out pdoPage and call pdoResources directly?
                      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
                    • Hi Bob,

                      Using just pdoResources, the date also disappears.
                        Frogabog- MODX Websites in Portland Oregon
                        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                        Having server issues? These guys have MODX Hosting perfected - SkyToaster