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

    I have situation where I am creating calls to action elements on a home page using pdoResources. I have the following code:

            [[pdoResources?
                &parents=`0`
                &depth=`1`
                &limit=`0`
                &context=`[[*context_key]]`
                &includeTVs=`categoryImage`
                &tvPrefix=``
                &where=`{"template:=":6, "OR:template:=":5}`
                &sortby=`menuindex`
                &sortdir=`ASC`
                &idx=`1`
                &showUnpublished=`0`
                &showHidden=`1`
                &tpl=`ctaTPL`
            ]]
    


    I need to show hidden resources because some of the resources at root level don't belong in the main menu or the calls to action section. So &showHidden=`1` is working (and I believe I don't even need to make the declaration because it's the default but if it's there or not, mkes no difference to my overall issue). However, I have one resource that is not hidden from menu but is unpublished but it still is rendered and I can't figure out how to get pdoResources to ignore it. Make the pdoResources call cached or uncached makes no difference.

    When I add &showLog=`1` I get the following result:

    0.0001562: pdoTools loaded
    0.0000339: xPDO query object created
    0.0004380: Included list of tvs: <b>categoryImage</b>
    0.0003159: leftJoined <i>modTemplateVarResource</i> as <b>TVcategoryimage</b>
    0.0006249: Added selection of <b>modResource</b>: <small>SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `richtext`, `template`, `menuindex`, `searchable`, `cacheable`, `createdby`, `createdon`, `editedby`, `editedon`, `deleted`, `deletedon`, `deletedby`, `publishedon`, `publishedby`, `menutitle`, `donthit`, `privateweb`, `privatemgr`, `content_dispo`, `hidemenu`, `class_key`, `context_key`, `content_type`, `uri`, `uri_override`, `hide_children_in_tree`, `show_in_tree`, `properties`</small>
    0.0000150: Added selection of <b>modTemplateVarResource</b>: <small>IFNULL(`value`, '') AS `categoryImage`</small>
    0.0000939: Replaced TV conditions
    0.0000441: Processed additional conditions
    0.0005131: Added where condition: <b>template:==6, OR:template:==5, modResource.published=1, modResource.deleted=0, modResource.context_key=web</b>
    0.0000281: Replaced TV conditions
    0.0001490: Sorted by <b>modResource.menuindex</b>, <b>ASC</b>
    0.0004420: SQL prepared <small>"SELECT SQL_CALC_FOUND_ROWS `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties`, IFNULL(`TVcategoryimage`.`value`, '') AS `categoryImage` FROM `modx_site_content` AS `modResource` LEFT JOIN `modx_site_tmplvar_contentvalues` `TVcategoryimage` ON `TVcategoryimage`.`contentid` = `modResource`.`id` AND `TVcategoryimage`.`tmplvarid` = 20 WHERE  ( `modResource`.`template` = 6 OR `modResource`.`template` = 5 AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 AND `modResource`.`context_key` = 'web' )  ORDER BY modResource.menuindex ASC "</small>
    0.0008121: SQL executed
    0.0000939: Total rows: <b>9</b>
    0.0001268: Rows fetched
    0.0052760: Prepared and processed TVs
    0.0017941: Loaded "modChunk" with name "ctaTPL"
    0.0149760: Returning processed chunks
    0.0242412: <b>Total time</b>
    12 320 768: <b>Memory usage</b>
    


    The row count is 9 but only 8 of the resources are published, 7 using template id of 6, of which one is unpublished and not hidden from menu, and 1 using template id of 5.

    I've checked the database for the resource that is unpublished and the published column value is 0, as it should be.

    I've also cleared the cache from within MODX. Cleared the cache using CacheClear and manually cleared the cache. The unpublished resource is always displayed.

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

      • 52064
      • 120 Posts
      Remove blank space before 0
        FerX - Developer at Eracom s.r.l.
      • Thanks. I was hoping it was something like that, but there are no blank spaces before 0. I'm assuming you mean in this statement:

        &showUnpublished=`0`
        


        If not where?

        I'm assuming that this statement in the log:

        0.0005131: Added where condition: <b>template:==6, OR:template:==5, modResource.published=1, modResource.deleted=0, modResource.context_key=web</b>
        


        Indicates that the resource has to be published, i.e. modResource.published=1.
        • discuss.answer
          • 52064
          • 120 Posts
          sorry for my error.
          Can you test sql command manual directly ?

          I think the problem is in the OR clause of SQL

          Try change the where
          &where=`{ "template:IN" : [ 5,6 ] }`
          

          Or
           &where=`{{"template:=":6, "OR:template:=":5}}`
          
            FerX - Developer at Eracom s.r.l.
          • &parents=`+0`
            coul solve this maybe.
            &parents=`0`
            means all parents and seems to to include a lot resources.
            • Quote from: ferx77 at Aug 27, 2016, 07:51 PM
              sorry for my error.
              Can you test sql command manual directly ?

              I think the problem is in the OR clause of SQL

              Try change the where
              &where=`{ "template:IN" : [ 5,6 ] }`
              

              Or
               &where=`{{"template:=":6, "OR:template:=":5}}`
              

              This did it:

              &where=`{ "template:IN" : [ 5,6 ] }`
              


              Thanks!
              • Please change &parents=`0` to &parents=`+0` too, otherwise &depth=`1` makes no sense.
                • Thanks, done.