Skip to content
Advertisement

How to get all categories of a wordpress site with rest api?

I’m trying to get all categories of my wordpress site with rest api :

        axios.get('https://../wp-json/wp/v2/categories').then((res) => {
            console.log(res.data);
        });

But it only returns me the latest 10 by default .

Query

/wp-json/wp/v2/categories

How can I get all categories of a wordpress site with rest api?

Advertisement

Answer

you can pass -1 in per_page argument for fetch all categories.

    axios.get('https://../wp-json/wp/v2/categories?per_page=-1').then((res) => {
        console.log(res.data);
    });

please check reference link: https://developer.wordpress.org/rest-api/reference/categories/#arguments

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement