PluginProbe
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / trunk
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid vtrunk
7.9.4 7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 All 87 releases
the-post-grid / app / Divi / Fields / ContentQuery.php
ContentQuery.php
296 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Divi Helper Class
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Divi\Fields;
9
10
11 use RT\ThePostGrid\Helpers\Fns;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Divi Helper Class
20 */
21 class ContentQuery {
22
23 public static function get_fields( $prefix = 'grid' ) {
24 $post_types = Fns::get_post_types();
25
26 $taxonomies = get_taxonomies( [], 'objects' );
27 $singlePostType = $post_types;
28 if ( rtTPG()->hasPro() ) {
29 $singlePostType = $post_types + [ 'current_query' => __( 'Current Query', 'the-post-grid' ) ];
30 }
31
32 $query_fields = [
33 'multiple_post_type' => [
34 'label' => esc_html__( 'Multiple Post Types?', 'the-post-grid' ),
35 'description' => esc_html__( 'If you enable Multiple Post Types the Front-end Filter will not work.', 'the-post-grid' ),
36 'type' => 'yes_no_button',
37 'options' => [
38 'on' => esc_html__( 'Yes', 'the-post-grid' ),
39 'off' => esc_html__( 'No', 'the-post-grid' ),
40 ],
41 'default' => 'off',
42 'show_if_not' => [
43 'post_type' => 'current_query',
44 ],
45 'tab_slug' => 'general',
46 'toggle_slug' => 'tpg_query',
47 ],
48
49 'post_type' => [
50 'label' => esc_html__( 'Post Source', 'the-post-grid' ),
51 'type' => 'select',
52 'options' => $singlePostType,
53 'default' => 'post',
54 'description' => Fns::get_pro_message( 'all post type.' ),
55 'show_if_not' => [
56 'multiple_post_type' => 'on',
57 ],
58 'tab_slug' => 'general',
59 'toggle_slug' => 'tpg_query',
60 ],
61 'post_types' => [
62 'label' => esc_html__( 'Post Sources', 'the-post-grid' ),
63 'type' => 'multiple_checkboxes',
64 'options' => $post_types,
65 'default' => [ 'post' ],
66 'description' => Fns::get_pro_message( 'all post type.' ),
67 'show_if' => [
68 'multiple_post_type' => 'on',
69 ],
70 'tab_slug' => 'general',
71 'toggle_slug' => 'tpg_query',
72 ],
73 'post_id' => [
74 'label' => esc_html__( 'Include only', 'the-post-grid' ),
75 'type' => 'text',
76 'description' => esc_html__( 'Enter the post IDs separated by comma for include', 'the-post-grid' ),
77 'placeholder' => 'Eg. 10, 15, 17',
78 'tab_slug' => 'general',
79 'toggle_slug' => 'tpg_query',
80 ],
81 'exclude' => [
82 'label' => esc_html__( 'Exclude', 'the-post-grid' ),
83 'type' => 'text',
84 'description' => esc_html__( 'Enter the post IDs separated by comma for exclude', 'the-post-grid' ),
85 'placeholder' => 'Eg. 12, 13',
86 'tab_slug' => 'general',
87 'toggle_slug' => 'tpg_query',
88 ],
89 'post_limit' => [
90 'label' => esc_html__( 'Limit', 'the-post-grid' ),
91 'type' => 'number',
92 'description' => esc_html__( 'The number of posts to show. Enter -1 to show all found posts.', 'the-post-grid' ),
93 'tab_slug' => 'general',
94 'toggle_slug' => 'tpg_query',
95 ],
96 'display_per_page' => [
97 'label' => esc_html__( 'Display Per Page', 'the-post-grid' ),
98 'type' => 'number',
99 'description' => esc_html__( 'Enter how may posts will display per page. It works only for the the pagination and ajax-filer.', 'the-post-grid' ),
100 'tab_slug' => 'general',
101 'toggle_slug' => 'tpg_query',
102 ],
103 'offset' => [
104 'label' => esc_html__( 'Offset', 'the-post-grid' ),
105 'type' => 'text',
106 'placeholder' => esc_html__( 'Enter Post offset', 'the-post-grid' ),
107 'description' => esc_html__( 'Number of posts to skip. The offset parameter is ignored when post limit => -1 is used.', 'the-post-grid' ),
108 'tab_slug' => 'general',
109 'toggle_slug' => 'tpg_query',
110 ],
111 'instant_query' => [
112 'label' => esc_html__( 'Quick Query', 'the-post-grid' ),
113 'type' => 'select',
114 'options' => [
115 'default' => esc_html__( '--Quick Query--', 'the-post-grid' ),
116 'popular_post_1_day_view' => esc_html__( 'Popular Post (1 Day View)', 'the-post-grid' ),
117 'popular_post_7_days_view' => esc_html__( 'Popular Post (7 Days View)', 'the-post-grid' ),
118 'popular_post_30_days_view' => esc_html__( 'Popular Post (30 Days View)', 'the-post-grid' ),
119 'popular_post_all_times_view' => esc_html__( 'Popular Post (All time View)', 'the-post-grid' ),
120 'most_comment_1_day' => esc_html__( 'Most Comment (1 Day)', 'the-post-grid' ),
121 'most_comment_7_days' => esc_html__( 'Most Comment (7 Days)', 'the-post-grid' ),
122 'most_comment_30_days' => esc_html__( 'Most Comment (30 Days)', 'the-post-grid' ),
123 'random_post_7_days' => esc_html__( 'Random Posts (7 Days)', 'the-post-grid' ),
124 'random_post_30_days' => esc_html__( 'Random Post (30 Days)', 'the-post-grid' ),
125 'related_category' => esc_html__( 'Related Posts (Category)', 'the-post-grid' ),
126 'related_tag' => esc_html__( 'Related Posts (Tag)', 'the-post-grid' ),
127 'related_cat_tag' => esc_html__( 'Related Posts (Tag and Category)', 'the-post-grid' ),
128 ],
129 'default' => 'default',
130 'description' => esc_html__( 'If you choose any value from here the orderby worn\'t work.', 'the-post-grid' ),
131 'tab_slug' => 'general',
132 'toggle_slug' => 'tpg_query',
133 ],
134 'tpg_heading_text_advanced_query' => [
135 'label' => esc_html__( 'Advanced Query', 'the-post-grid' ),
136 'type' => 'text',
137 'tab_slug' => 'general',
138 'toggle_slug' => 'tpg_query',
139 ],
140 ];
141
142 $_url = site_url( 'wp-admin/edit.php?post_type=rttpg&page=tgp_taxonomy_order' );
143
144 foreach ( $taxonomies as $taxonomy => $object ) {
145 if ( ! isset( $object->object_type[0] )
146 || ! in_array( $object->object_type[0], array_keys( $post_types ) )
147 || in_array( $taxonomy, Fns::get_excluded_taxonomy() )
148 ) {
149 continue;
150 }
151
152 $taxonomy_lists = Fns::tpg_get_categories_by_id( $taxonomy, 'term_id' );
153
154 $query_fields[ $taxonomy . '_ids' ] = [
155 'label' => esc_html__( 'By ', 'the-post-grid' ) . $object->label,
156 'type' => 'multiple_checkboxes',
157 'options' => $taxonomy_lists,
158 'show_if' => [ 'post_type' => $object->object_type, ],
159 'show_if_not' => [ 'multiple_post_type' => 'on' ],
160 'description' => "For custom order: <a target='_blank' href='" . $_url . "'>The Post Grid > Taxonomy Order</a>. NB: The terms are currently displayed in the order of their term_id",
161 'tab_slug' => 'general',
162 'toggle_slug' => 'tpg_query',
163 'columns' => 2,
164 ];
165
166 if(! empty($taxonomy_lists)) {
167 $query_fields[ $taxonomy . '_ids2' ] = [
168 'label' => esc_html__( 'By ', 'the-post-grid' ) . $object->label,
169 'type' => 'multiple_checkboxes',
170 'options' => $taxonomy_lists,
171 'show_if' => [
172 'multiple_post_type' => 'on',
173 ],
174 'description' => "For custom order: <a target='_blank' href='" . $_url . "'>The Post Grid > Taxonomy Order</a>",
175 'tab_slug' => 'general',
176 'toggle_slug' => 'tpg_query',
177 'columns' => 2,
178 ];
179 }
180 }
181
182 $orderby_opt = [
183 'date' => esc_html__( 'Date', 'the-post-grid' ),
184 'ID' => esc_html__( 'Order by post ID', 'the-post-grid' ),
185 'author' => esc_html__( 'Author', 'the-post-grid' ),
186 'title' => esc_html__( 'Title', 'the-post-grid' ),
187 'modified' => esc_html__( 'Last modified date', 'the-post-grid' ),
188 'parent' => esc_html__( 'Post parent ID', 'the-post-grid' ),
189 'comment_count' => esc_html__( 'Number of comments', 'the-post-grid' ),
190 'menu_order' => esc_html__( 'Menu order', 'the-post-grid' ),
191 ];
192
193 if ( rtTPG()->hasPro() ) {
194 $prderby_pro_opt = [
195 'include_only' => esc_html__( 'Include Only', 'the-post-grid' ),
196 'rand' => esc_html__( 'Random order', 'the-post-grid' ),
197 'meta_value' => esc_html__( 'Meta value', 'the-post-grid' ), //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
198 'meta_value_num' => esc_html__( 'Meta value number', 'the-post-grid' ),
199 'meta_value_datetime' => esc_html__( 'Meta value datetime', 'the-post-grid' ),
200 ];
201 $orderby_opt = array_merge( $orderby_opt, $prderby_pro_opt );
202 }
203
204 $query_fields_2 = [
205 'relation' => [
206 'label' => esc_html__( 'Taxonomies Relation', 'the-post-grid' ),
207 'type' => 'select',
208 'default' => 'OR',
209 'options' => [
210 'OR' => __( 'OR', 'the-post-grid' ),
211 'AND' => __( 'AND', 'the-post-grid' ),
212 ],
213 'tab_slug' => 'general',
214 'toggle_slug' => 'tpg_query',
215 ],
216 'author' => [
217 'label' => esc_html__( 'By Author', 'the-post-grid' ),
218 'options' => Fns::rt_get_users(),
219 'tab_slug' => 'general',
220 'toggle_slug' => 'tpg_query',
221 ],
222 'post_keyword' => [
223 'label' => esc_html__( 'By Keyword', 'the-post-grid' ),
224 'type' => 'text',
225 'placeholder' => esc_html__( 'Search by keyword', 'the-post-grid' ),
226 'description' => esc_html__( 'Search by post title or content keyword', 'the-post-grid' ),
227 'tab_slug' => 'general',
228 'toggle_slug' => 'tpg_query',
229 ],
230 'date_range' => [
231 'label' => esc_html__( 'Date Range (Start - End)', 'the-post-grid' ),
232 'type' => 'text',
233 'placeholder' => esc_html__( '2025-02-22 to 2025-05-30', 'the-post-grid' ),
234 'description' => esc_html__( 'Enter a date range in the format: 2025-02-22 to 2025-05-30. Use "to" to separate the start and end dates.', 'the-post-grid' ),
235 'tab_slug' => 'general',
236 'toggle_slug' => 'tpg_query',
237 ],
238 'orderby' => [
239 'label' => esc_html__( 'Order by', 'the-post-grid' ),
240 'type' => 'select',
241 'options' => $orderby_opt,
242 'default' => 'date',
243 'description' => Fns::get_pro_message( 'Random Order.' ),
244 'show_if' => [
245 'instant_query' => 'default',
246 ],
247 'tab_slug' => 'general',
248 'toggle_slug' => 'tpg_query',
249 ],
250 'meta_key' => [
251 'label' => esc_html__( 'Meta Key', 'the-post-grid' ),
252 'type' => 'text',
253 'placeholder' => esc_html__( 'Enter Meta Key.', 'the-post-grid' ),
254 'show_if' => [
255 'orderby' => [ 'meta_value', 'meta_value_num', 'meta_value_datetime' ],
256 ],
257 'tab_slug' => 'general',
258 'toggle_slug' => 'tpg_query',
259 ],
260 'order' => [
261 'label' => esc_html__( 'Sort order', 'the-post-grid' ),
262 'type' => 'select',
263 'options' => [
264 'ASC' => esc_html__( 'ASC', 'the-post-grid' ),
265 'DESC' => esc_html__( 'DESC', 'the-post-grid' ),
266 ],
267 'default' => 'DESC',
268 'tab_slug' => 'general',
269 'toggle_slug' => 'tpg_query',
270 ],
271 'ignore_sticky_posts' => [
272 'label' => esc_html__( 'Ignore sticky posts at the top', 'the-post-grid' ),
273 'type' => 'yes_no_button',
274 'options' => [
275 'on' => esc_html__( 'Yes', 'the-post-grid' ),
276 'off' => esc_html__( 'No', 'the-post-grid' ),
277 ],
278 'default' => 'off',
279 'tab_slug' => 'general',
280 'toggle_slug' => 'tpg_query',
281 ],
282 'no_posts_found_text' => [
283 'label' => esc_html__( 'No post found Text', 'the-post-grid' ),
284 'type' => 'text',
285 'default' => esc_html__( 'No posts found.', 'the-post-grid' ),
286 'placeholder' => esc_html__( 'Enter No post found', 'the-post-grid' ),
287 'tab_slug' => 'general',
288 'toggle_slug' => 'tpg_query',
289 ],
290 ];
291
292 return array_merge( $query_fields, $query_fields_2 );
293 }
294
295 }
296