Skip to content

Commit 759607c

Browse files
committed
Merge branch 'hotfix/empty-taxonimies'
2 parents a0e8f4a + ac6149c commit 759607c

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

better-wp-endpoints.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Better WordPress Endpoints
44
Plugin URI: https://github.com/factor1/better-wp-endpoints/
55
Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
6-
Version: 0.1.5
6+
Version: 0.1.6
77
Author: Eric Stout, Factor1 Studios
88
Author URI: https://factor1studios.com/
99
License: GPL3

includes/get_post_by_id.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ function get_post_by_id( $data ) {
4343
$bwe_categories = [];
4444
$bwe_category_ids = [];
4545

46-
foreach ($categories as $key => $category) {
47-
array_push($bwe_category_ids, $category->term_id);
48-
array_push($bwe_categories, $category->cat_name);
46+
if( !empty($categories) ){
47+
foreach ($categories as $key => $category) {
48+
array_push($bwe_category_ids, $category->term_id);
49+
array_push($bwe_categories, $category->cat_name);
50+
}
4951
}
5052

5153
$bwe_post->category_ids = $bwe_category_ids;
@@ -61,9 +63,11 @@ function get_post_by_id( $data ) {
6163
$bwe_tags = [];
6264
$bwe_tag_ids = [];
6365

64-
foreach ($tags as $key => $tag) {
65-
array_push($bwe_tag_ids, $tag->term_id);
66-
array_push($bwe_tags, $tag->name);
66+
if( !empty($tags) ){
67+
foreach ($tags as $key => $tag) {
68+
array_push($bwe_tag_ids, $tag->term_id);
69+
array_push($bwe_tags, $tag->name);
70+
}
6771
}
6872

6973
$bwe_post->tag_ids = $bwe_tag_ids;

includes/get_posts.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ function bwe_get_posts( WP_REST_Request $request ) {
6464
$bwe_categories = [];
6565
$bwe_category_ids = [];
6666

67-
foreach ($categories as $key => $category) {
68-
array_push($bwe_category_ids, $category->term_id);
69-
array_push($bwe_categories, $category->cat_name);
67+
if( !empty($categories) ){
68+
foreach ($categories as $key => $category) {
69+
array_push($bwe_category_ids, $category->term_id);
70+
array_push($bwe_categories, $category->cat_name);
71+
}
7072
}
7173

7274
$bwe_post->category_ids = $bwe_category_ids;
@@ -82,11 +84,14 @@ function bwe_get_posts( WP_REST_Request $request ) {
8284
$bwe_tags = [];
8385
$bwe_tag_ids = [];
8486

85-
foreach ($tags as $key => $tag) {
86-
array_push($bwe_tag_ids, $tag->term_id);
87-
array_push($bwe_tags, $tag->name);
87+
if( !empty($tags) ){
88+
foreach ($tags as $key => $tag) {
89+
array_push($bwe_tag_ids, $tag->term_id);
90+
array_push($bwe_tags, $tag->name);
91+
}
8892
}
8993

94+
9095
$bwe_post->tag_ids = $bwe_tag_ids;
9196
$bwe_post->tag_names = $bwe_tags;
9297

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "better-wp-endpoints",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Serves up slimmer WordPress Rest API endpoints.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)