Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3355120
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:21:24+00:00 2026-05-18T02:21:24+00:00

I’m attempting the modify this Modx Snippet so that it will accept multiple values

  • 0

I’m attempting the modify this Modx Snippet so that it will accept multiple values being returned from the db instead of the default one.

tvTags, by default, was only meant to be set to one variable. I modified it a bit so that it’s exploded into a list of variables. I’d like to query the database for each of these variables and return the tags associated with each. However, I’m having difficulty as I’m fairly new to SQL and PHP.

I plugged in $region and it works, but I’m not really sure how to add in more WHERE clauses for the $countries variable.

Thanks for your help!

if (!function_exists('getTags')) {

    function getTags($cIDs, $tvTags, $days) {

        global $modx, $parent;

        $docTags = array ();

        $baspath= $modx->config["base_path"] . "manager/includes";
        include_once $baspath . "/tmplvars.format.inc.php";
        include_once $baspath . "/tmplvars.commands.inc.php";

        if ($days > 0) {
            $pub_date = mktime() - $days*24*60*60;
        } else {
            $pub_date = 0;
        }

        list($region, $countries) = explode(",", $tvTags);

        $tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
        $tb2 = $modx->getFullTableName("site_tmplvars");
        $tb_content = $modx->getFullTableName("site_content");
        $query = "SELECT stv.name,stc.tmplvarid,stc.contentid,stv.type,stv.display,stv.display_params,stc.value";
        $query .= " FROM ".$tb1." stc LEFT JOIN ".$tb2." stv ON stv.id=stc.tmplvarid ";
        $query .= " LEFT JOIN $tb_content tb_content ON stc.contentid=tb_content.id ";
        $query .= " WHERE stv.name='".$region."' AND stc.contentid IN (".implode($cIDs,",").") ";
        $query .= " AND tb_content.pub_date >= '$pub_date' ";
        $query .= " AND tb_content.published = 1 ";
        $query .= " ORDER BY stc.contentid ASC;";

        $rs = $modx->db->query($query);
        $tot = $modx->db->getRecordCount($rs);
        $resourceArray = array();
        for($i=0;$i<$tot;$i++)  {
            $row = @$modx->fetchRow($rs);
            $docTags[$row['contentid']]['tags'] = getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);   
        }
            if ($tot != count($cIDs)) {
            $query = "SELECT name,type,display,display_params,default_text";
            $query .= " FROM $tb2";
            $query .= " WHERE name='".$region."' LIMIT 1";
            $rs = $modx->db->query($query);
            $row = @$modx->fetchRow($rs);
            $defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
            foreach ($cIDs as $id) {
                if (!isset($docTags[$id]['tags'])) {
                    $docTags[$id]['tags'] = $defaultOutput;
                }
            }
        }
            return $docTags;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:21:25+00:00Added an answer on May 18, 2026 at 2:21 am

    You don’t add in more WHERE clauses, you use ANDs and ORs in the already existing where clause. I would say after the line $query .= " WHERE stv.name = '".$region... you put in

    foreach ($countries as $country)
    {
        $query .= "OR stv.name = '{$country}', ";
    }
    

    but I don’t know how you want the query to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.