Skip to content

Commit

Permalink
Latest posts: Only request required category fields. (#4179)
Browse files Browse the repository at this point in the history
We were requesting all category fields while needing three of them, this change makes sure we request only the fields we need.
  • Loading branch information
jorgefilipecosta authored Dec 27, 2017
1 parent c5a8db5 commit 34c81b4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions blocks/query-panel/category-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { get } from 'lodash';
import { stringify } from 'querystringify';

/**
* WordPress dependencies
Expand All @@ -24,8 +25,14 @@ function CategorySelect( { label, noOptionLabel, categories, selectedCategory, o
);
}

const applyWithAPIData = withAPIData( () => ( {
categories: '/wp/v2/categories',
} ) );
const applyWithAPIData = withAPIData( () => {
const query = stringify( {
per_page: 100,
_fields: [ 'id', 'name', 'parent' ],
} );
return {
categories: `/wp/v2/categories?${ query }`,
};
} );

export default applyWithAPIData( CategorySelect );

0 comments on commit 34c81b4

Please sign in to comment.