vaersaagod / seomate

SEO, mate! It's important. That's why SEOMate provides the tools you need to craft all the meta tags, sitemaps and JSON-LD microdata you need - in one highly configurable, open and friendly package - with a super-light footprint.
MIT License
36 stars 8 forks source link

Add ability to target relational queries in criteria for sitemap Feature Request #62

Closed zhua89cc closed 2 years ago

zhua89cc commented 2 years ago

Hi there, We have a scenario in which we want to remove certain pages from our sitemap based on relational query results. We have two category groups in which entries are tagged to them and ideally only want the category pages in our sitemap that have more than a certain amount of entries associated with them. Based on documentation in the config we can filter in criteria based on section, category group name, even values of a field like

  'policy' => [
    'changefreq' => 'daily',
    'priority' => .7,
    'criteria' => [
      'section' => 'policy',
      'pageHidden' => 'not true'
    ],
  ],

Would love to be able to pass in a relational query to the criteria to only show greater than x number as an example.

Craft CMS Version 3.7.43 SEO Mate Version 1.1.13

mmikkel commented 2 years ago

Generally, the criteria key supports any and all core element query params, using bracket notation – so to add relational criteria you can add a relatedTo param to the 'criteria' array. Basically, anything you can do with the core 'relatedTo' param, you can do here as well.

TBH your use case (limiting results to entries that are related to categories related to a total count of entries above a certain number, if I understand correctly) sounds pretty difficult to pull off – but the limiting factor to what you can achieve is going to be Craft's relatedTo feature, not SEOMate as such.

FYI based on the example above your syntax for the 'policy' sitemap looks a bit off. The expanded criteria syntax (which is necessary to actually define the 'criteria') should look like this:

'policy' => [
    'elementType' => \craft\elements\Entry::class,
    'criteria' => [
        'section' => 'policy', 
        'pageHidden' => 'not true',
    ],
    'params' => [
        'changefreq' => 'daily', 
        'priority' => 0.7
    ],
],

Check out "Enabling sitemaps" to see more examples.