Excludes document from attachments list via API using exlude on media request.

This commit is contained in:
Mateus Machado Luna 2019-08-22 17:37:11 -03:00
parent 628e96e09f
commit 66dba13d85
1 changed files with 8 additions and 3 deletions

View File

@ -206,11 +206,16 @@ export const fetchAttachments = ({ commit }, { page, attachmentsPerPage, itemId,
commit('cleanAttachments');
commit('setTotalAttachments', null);
let endpoint = '/media/?parent=' + itemId + '&per_page=' + attachmentsPerPage + '&page=' + page;
if (documentId)
endpoint += '&exclude=' + documentId;
return new Promise((resolve, reject) => {
axios.wp.get('/media/?parent=' + itemId + '&per_page=' + attachmentsPerPage + '&page=' + page)
axios.wp.get(endpoint)
.then(res => {
let attachments = res.data.filter((attachment) => attachment.id != documentId);
let total = (documentId && res.data.length != attachments.length && res.headers['x-wp-total'] > 0) ? res.headers['x-wp-total'] - 1 : res.headers['x-wp-total'];
let attachments = res.data;
let total = res.headers['x-wp-total'];
commit('setAttachments', attachments);
commit('setTotalAttachments', total);