Override 'per_page' per post-type

Hi, I’m wondering if it’s possible to have a different per_page parameter per post-type. Per example I want the blogs archive to show 10 posts at most, but the portfolio archive should show 20 posts.

This is my configuration in frontity.settings.js:

...
"state": {
        "source": {
          "api": "https://frontity.noesteprojecten.nl/wp-json",
          "homepage": "/web-app-development",
          params: {
            per_page: 20,
          },
          postTypes: [
            {
              type: "post",
              endpoint: "posts",
              archive: "/blogs",
            },
            {
              type: "portfolio",
              endpoint: "portfolio",
              archive: "/portfolio-archive",
            },
            {
              type: "wp_template_part",
              endpoint: "template-parts",
            },
          ]
        },
      }
...

How to configure this per post-type? I’d expect to be able to use the per_post parameter per post-type, but it doesn’t work for me when I do it like this:

...
"state": {
        "source": {
          "api": "https://frontity.noesteprojecten.nl/wp-json",
          "homepage": "/web-app-development",
          params: {
            per_page: 20,
          },
          postTypes: [
            {
              type: "post",
              endpoint: "posts",
              archive: "/blogs",
              params: {
                per_page: 10,
              },
            },
            {
              type: "portfolio",
              endpoint: "portfolio",
              archive: "/portfolio-archive",
            },
            {
              type: "wp_template_part",
              endpoint: "template-parts",
            },
          ]
        },
      }
...

Hi @dominique

You can assign a per_page parameter to a taxonomy: https://docs.frontity.org/api-reference-1/wordpress-source#state-source-taxonomies

It’s not a solution, I know, but more of a workaround, but you could assign all the portfolio posts to a single generic category and fetch them that way, then they would display 20 per page (or whatever you define).

Meanwhile I’m checking with our dev team to see if there’s a proper solution to this.

Thanks for the suggestion, indeed it’s a (bit of a creative) workaround. It’d be great if it could be configured per post-type in the settings.

Hey @dominique !

Indeed, there is not a way to achieve this per post type currently, sorry! We are aware of it and have it on our roadmap: Source: Add params to postTypes

In the meantime, you can use the solution suggested by @mburridge (nice workaround, Michael :slight_smile: )

1 Like

Hey, @dominique if this is a feature that you would need it would be awesome if you made a pull request to frontity with it :slight_smile:

I think it should just be a couple lines of code! You could have a look at how params are passed to the request in the taxonomy handler and just port it to the postType handler.

I ll be happy to assist if you have any doubts :slight_smile: