{"_id":"57fa6be09a19ad0e006e7d80","parentDoc":null,"project":"5668fab608f90021008e882f","category":{"_id":"57fa65275ba65a17008b988f","__v":0,"version":"5668fab608f90021008e8832","project":"5668fab608f90021008e882f","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-10-09T15:41:27.321Z","from_sync":false,"order":7,"slug":"model-query-javascript","title":"Model query (Javascript)"},"user":"5668fa9755e4b32100935d41","version":{"_id":"5668fab608f90021008e8832","__v":19,"project":"5668fab608f90021008e882f","createdAt":"2015-12-10T04:08:22.769Z","releaseDate":"2015-12-10T04:08:22.769Z","categories":["5668fab708f90021008e8833","569740f124490c3700170a64","569742b58560a60d00e2c25d","569742bd0b09a41900b2446c","569742cd69393517000c82b3","569742f459a6692d003fad8f","569743020b09a41900b2446d","5697430b69393517000c82b5","56a17776470ae00d00c30642","56a2c48a831e2a0d0069b1ad","56b535757bccae0d00e9a1cd","56e1ff6aa49fdc0e005746b5","57e1c88115bf6522002a5e4e","57fa65275ba65a17008b988f","57fbeea34002550e004c032e","58474584889b6c2d00fb86e9","58475dcc64157f0f002f1907","587e7b5158666c2700965d4e","58a349fc30852819007ba083"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.18.0","version":"1.18"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-10-09T16:10:08.550Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"You can set a maximum allowed age for the items recommended. Note that this feature will work *only* if you are sharing the `published_time` in the inventory metadata. For more on sharing that information, see the [fields with timestamps section of Defining your Inventory](https://liftigniter.readme.io/docs/defining-your-inventory#fields-with-timestamps).\n\nYou need to specify the maximum age in seconds with the field name `maxAgeInSeconds` inside the opts of your query. Here is how you would make such a query if you want to limit results to 1 day old:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p('register', {\\n                  max: 10, // Large number requested so you can see our full range of items\\n\\t\\t          widget: 'default-widget', // name of widget\\n\\t\\t          opts: {maxAgeInSeconds: 86400},\\n                  callback: function(resp) {\\n                    console.log(JSON.stringify(resp, null, 2));\\n                    console.log(\\\"// TEST.\\\");\\n                  }\\n               }\\n);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nSince the restrictions are placed separately for each registered widget, you have the flexibility of setting different restrictions based on the widget, as well as changing the age restrictions over time.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Corresponding option for model query API endpoint\"\n}\n[/block]\nIf using the model query API endpoint, you can pass the maximum age in seconds with the parameter name `maxAgeInseconds`. For more details, see the [model query API endpoint documentation](doc:model).","excerpt":"","slug":"set-max-age-for-recommended-items","type":"basic","title":"Set max age for recommended items"}

Set max age for recommended items


You can set a maximum allowed age for the items recommended. Note that this feature will work *only* if you are sharing the `published_time` in the inventory metadata. For more on sharing that information, see the [fields with timestamps section of Defining your Inventory](https://liftigniter.readme.io/docs/defining-your-inventory#fields-with-timestamps). You need to specify the maximum age in seconds with the field name `maxAgeInSeconds` inside the opts of your query. Here is how you would make such a query if you want to limit results to 1 day old: [block:code] { "codes": [ { "code": "$p('register', {\n max: 10, // Large number requested so you can see our full range of items\n\t\t widget: 'default-widget', // name of widget\n\t\t opts: {maxAgeInSeconds: 86400},\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n console.log(\"// TEST.\");\n }\n }\n);", "language": "javascript" } ] } [/block] Since the restrictions are placed separately for each registered widget, you have the flexibility of setting different restrictions based on the widget, as well as changing the age restrictions over time. [block:api-header] { "type": "basic", "title": "Corresponding option for model query API endpoint" } [/block] If using the model query API endpoint, you can pass the maximum age in seconds with the parameter name `maxAgeInseconds`. For more details, see the [model query API endpoint documentation](doc:model).