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

    Is there a way, to get the id for a document, where I only know the alias?

    Regards,
    sucram
      • 24719
      • 194 Posts
      you could query the db, something like:

      $id = $modx->db->select(’id’, $modx->getFullTableName(’site_content’), ’`alias`=’.$alias);
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        The alias listing is stored in the site cache file, and is made available as an array. It looks like you want $modx->documentListing.
        $d = &$this->documentListing;
        ...
        $d['index'] = 1;
        $d['blog'] = 2;
        $d['add-a-blog-entry'] = 3;
        ...
        

        The array key is the alias, and the value is the ID.

        The parser uses this code:
         if (array_key_exists($alias, $this->documentListing)) {
        $this->documentIdentifier= $this->documentListing[$alias];

        You would need to change the $this to $modx to use the code in a snippet.
          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
          • 28796
          • 23 Posts
          Thanks a lot ...

          The code above was exactly what I was looking for ...

          sucram