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

    I am writing a plugin to set a placeholder that will be used to print out the articles a user has written that will display on their profile. I am not getting any output. Does anyone know what I’m doing wrong?

    /* 
    * This plugin detects the user's user id through the modx api and displays the articles that have been posted by that user.
    * Created: 19-10-2007
    * Author: Sarah Vardy
    */
    
    $uid = '';
    $parentID = 48;
    $articleListingForUser = '';
    
    // Set uid to the login user id
    $uid = modx->getLoginUserID();
    
    // Query the database to find out what articles have been posted by the user
    
    //select the modx table to use
    $table = $modx->getFullTableName("site_content");
    
    //iterate through the table and see what articles have been posted by the user
    
    $result = $modx->db->select('*', $table); 
    
    //while there are still more rows in the table check to see if the user is logged in
    
    while ($r = $modx->db->getRow($result))   
    { 
         $id = $r['id'];
         $createdby = $r['createdby'];
         $parent = $r['parent'];
          
          //if parent equals parentID (document container for news articles) and createdby equals uid print 
          if ($parent == $parentID && $createdby == $uid)
          {
                //list this document
                $articleListingForUser = $createdby . ',';
          }
    }
    //Trim any leading or trailing commas and spaces from the string of articles
    $articleListingForUser = trim($articleListingForUser, " \,");
    
    //Set the placeholder to display the number of articles the user has posted
    $modx->setPlaceholder('articleListingForUser', "($articleListingForUser)");