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

    I have a URL link with a tag= value. However, the value for the tag includes commas, & and whitespaces, therefore the tag value in my URL only shows the first word of my tag value string.

    I am using xpdo to interact with my database tables. Here is what my xpdo call look like:

    $tag = $_GET["tag"];

    foreach ($result as $r){
    $resource[] = $modx->getObject('modTemplateVarResource', array (
    'tmplvarid' => 8,
    'value' => $tag,
    'contentid'=> $id,
    ));

    }

    In my db table, the value is 'Agencies and Sponsors'. Whereas in my URL, the tag value is "Agencies". Is there a way, using XPDO to query this so that it will match "Agencies" with "Agencies and Sponsors" from the table??
      • 40706
      • 128 Posts
      Maybe you could use FIND_IN_SET

      $tag = $modx->quote($_GET['tag']);
      foreach ($result as $r){
      	$resource[] = $modx->getObject('modTemplateVarResource', array (
      		'tmplvarid' => 8,
      		"FIND_IN_SET({$tag}, value) > 0",
      		'contentid'=> $id,
      	));
      }
      
        • 3749
        • 24,544 Posts
        or LIKE %tag%


        $tag = $modx->quote($_GET['tag']);
        foreach ($result as $r){
            $c = $modx->newQuery('modTemplateVarResource');
            $c->where(array(
                'tmplvarid' => 8,
                'contentid' => $id, // I assume you're setting $id somewhere
                'value:LIKE' => '%' . $tag . '%',
            ));
            $resource[] = $modx->getObject('modTemplateVarResource', $c);
        }
        [ed. note: BobRay last edited this post 11 years, 3 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