json_prepare_post filter, remove/adapt the retrieved data
-
Hello,
With the filter
json_prepare_posti’m trying to adapt (and remove) some of the data returned when doing a request with these parameters/wp-json/posts?filter[name]=contact&type[]=page. I gave my filter callback a very high priority (999), so as to hook it after all others.It works fine as long as the page has no featured image. I dumped each callback for the json_prepare_post filter and just before it is applied in WP_JSON_Posts->prepare_post (1°). Without a featured image this the chronology I get:
1° before applying filter json_prepare_post for page
2° add_post_author_data for page
3° add_thumbnail_data for page
4° add_term_data for page
5° CUSTOM json_prepare_post for pageMy own callback (5°) is indeed the last one and I can remove the array elements I want. But when the page has a featured image, my custom callback is only called for the featured image/attachment (6°). Although the json_prepare_post filter is applied twice: once for the page (1°) and once for the attachment (3°).
1° before applying filter json_prepare_post for page
2° add_post_author_data for page
3° before applying filter json_prepare_post for attachment
4° add_post_author_data for attachment
5° add_term_data for attachment
6° CUSTOM json_prepare_post for attachment
7° add_thumbnail_data for page
8° add_term_data for pageIf I give my custom callback a priority lower than 10, which is the priority of the default callbacks of the plugin, it is called twice, but too early off course:
1° before applying filter json_prepare_post for page
2° CUSTOM json_prepare_post for page
3° add_post_author_data for page
4° before applying filter json_prepare_post for attachment
5° CUSTOM json_prepare_post for attachment
6° add_post_author_data for attachment
7° add_term_data for attachment
8° add_thumbnail_data for page
9° add_term_data for pageAny clue?
Thanks!
The topic ‘json_prepare_post filter, remove/adapt the retrieved data’ is closed to new replies.