This repository was archived by the owner on Feb 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftWordPress.js
109 lines (75 loc) · 2.21 KB
/
ftWordPress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
angular.module('FireTree.ngWordPress', [])
/**
* A simple example service that returns some data.
*/
.factory('ftWordPress', function( $http ) {
var wpURL = '<YOUR WORDPRESS URL>';
var callback = '_jsonp=JSON_CALLBACK';
return {
/**
* Return a Custom Post Type
*
* cpt string Custom post type
* filters array Array of filters. Ex. [{ filter: 'posts_per_page', value: '5' }]
*/
getCPT: function( cpt, filters ) {
// Define the endpoint
var apiURL = wpURL + '/wp-json/posts?type=' + cpt;
// Loop through the filters and add them to the endpoint
for (var i=0; i < filters.length; i++) {
apiURL += '&filter[' + filters[i].filter + ']=' + filters[i].value;
}
apiURL += '&' + callback;
// Return the data
return $http.jsonp( apiURL );
},
/**
* Returns the menu for a specific menu location
*
* Requires https://wordpress.org/plugins/wp-api-menus/
* Will rewrite for the WP REST API when this functionality is included.
*
* name string The name of the menu location
*/
getMenuThemeLocation: function( name ) {
// Define the endpoint
var apiURL = wpURL + '/wp-json/menu-locations/' + name + '?' + callback;
// Return the data
return $http.jsonp( apiURL );
},
/**
* Return a Post
*
* id string The Post ID
*/
getPost: function( id ) {
// Define the endpoint
var apiURL = wpURL + '/wp-json/posts/' + id + '?' + callback;
// Return the data
return $http.jsonp( apiURL );
},
/**
* Return a Taxonomy Term
*
* taxonomy string The Taxonomy to return
* id string The ID of the term to return
*/
getTerm: function( taxonomy, id ) {
// Define the endpoint
var apiURL = wpURL + '/wp-json/taxonomies/' + taxonomy + '/terms/' + id + '?' + callback;
// Return the data
return $http.jsonp( apiURL );
},
/**
* Return Taxonomy Terms
*
* taxonomy string The Taxonomy to return terms for
*/
getTerms: function( taxonomy ) {
// Define the endpoint
var apiURL = wpURL + '/wp-json/taxonomies/' + taxonomy + '/terms?' + callback;
// Return the data
return $http.jsonp( apiURL );
}
}
});