We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41294
    • 34 Posts
    I used getResources/getPage extra to query all the items i want to list. But there are 2 filter options to filter the display of queried items.

    Scenario:

    There are 2 filter/sort options "Key" and "Type", if a user chooses "Key" option, the "Key" value will be compared to every resources TVs(i.e. tv.item_description, tv.item_name) and fields (i.e. pagetitle, description).

    It's like using this logic using &where
    {"tv.item_description:LIKE":Key_Value, "OR:pagetitle:LIKE":Key_Value}


    if only someone could tell me how to use TVs and Fields using &where of getResources.. I know fields (i.e. pagetitle, description, alias) can easily be queried to the JSON using &where, but is there a way using TVs too? The problem also with &tvFilters is that i can't filter Fields just TVs.. Maybe there's a way to filter both?

    Thanks wink
      • 44234
      • 219 Posts
      Is 'Key_Value' a TV as well? [ed. note: davidpede last edited this post 13 years, 1 month ago.]
        Find me on Twitter, GitHub or Google+
        • 47571
        • 2 Posts
        If anyone is still looking for an answer to this, I couldn't find one, so I made a solution/hack.

        I am using a search field sending a get variable, but this could be hard-coded as well. I am getting the value of that using the fastField plugin.

        First I am making the getResources call with a few output modifiers to include the current resource as a parent if no search has been made. I am also including a custom snippet in the resources section that will run custom MySQL queries to determine if a resource is a match.

        [[!getResources?
        	&parents=`[[!#get.s:notempty=`-1`:empty=`[[*id]]`]]`
        	&resources=`[[!resourceSearch? &parent=`[[*id]]`]]`
        	&tpl=`getLocations`
        	&sortby=`menuindex, id`
        	&sortdir=`ASC`
        	&limit=`0`
        	&includeTVs=`1`
        	&includeContent=`1`
        ]]
        


        As for the snippet itself, here is what I have. It is checking the content and TV content tables in MODx against my search query.

        	$s = $_GET['s'];
        	$resources = '';
        
        //Connection Info
        	include(MODX_CORE_PATH.'config/config.inc.php');
        	$link = mysqli_connect($database_server, $database_user, $database_password, $dbase) or die("Error " . mysqli_error($link));
        
        //Query
        	$query = "SELECT DISTINCT modx_site_content.id
        FROM modx_site_tmplvar_contentvalues 
        INNER JOIN modx_site_content
        ON modx_site_tmplvar_contentvalues.contentid=modx_site_content.id
        WHERE
        	(
        	modx_site_content.parent = '".$parent."' 
        	AND modx_site_content.pagetitle LIKE '%".$s."%'
        	) OR (
        	modx_site_content.parent = '".$parent."' 
        	AND modx_site_tmplvar_contentvalues.tmplvarid = '14' 
        	AND modx_site_tmplvar_contentvalues.value LIKE '%".$s."%'
        	) OR (
        	modx_site_content.parent = '".$parent."' 
        	AND modx_site_tmplvar_contentvalues.tmplvarid = '2' 
        	AND modx_site_tmplvar_contentvalues.value LIKE '%".$s."%'
        	)";
        	$sql = $link->query($query);
        	$i = 0;
        	while ($row = mysqli_fetch_assoc($sql)){
        		if ($i > 0) {$resources .= ',';}
        		$resources .= $row['id'];
        		$i++;
        	}
        
        //echo all resource ids that matched
        	echo $resources;
        
        mysqli_free_result($sql);
        mysqli_close($link);
        


        Hopefully this helps someone!