List category posts - Version 0.75

Version Description

  • Improvements to custom_fields and customfield_orderby. Please check the readme for more information.
  • Several bug fixes to pagination.
  • Do not hide empty categories from widget. Special thanks to Klemens Starybrat (zymeth25) for all the contributions.
Download this release

Release Info

Developer fernandobt
Plugin Icon 128x128 List category posts
Version 0.75
Comparing to
See all releases

Code changes from version 0.74.2 to 0.75

include/lcp-catlistdisplayer.php CHANGED
@@ -295,7 +295,7 @@ class CatListDisplayer {
295
  }
296
 
297
  private function get_pagination(){
298
- $this->catlist->get_pagination();
299
  }
300
 
301
  /*
295
  }
296
 
297
  private function get_pagination(){
298
+ return $this->catlist->get_pagination();
299
  }
300
 
301
  /*
include/lcp-paginator.php CHANGED
@@ -27,8 +27,7 @@ class LcpPaginator {
27
  return !empty($pagination) &&
28
  $pagination == 'yes' ||
29
  (get_option('lcp_pagination') === 'true' &&
30
- ($lcp_pag_present &&
31
- $pagination !== 'false')
32
  );
33
  }
34
 
@@ -95,9 +94,9 @@ class LcpPaginator {
95
  "#lcp_instance_" . $lcp_instance;
96
  $link .= "<li><a href='$page_link' title='$page'";
97
  if ($page === $this->prev_page_num) {
98
- $link .= "class='lcp_prevlink'";
99
  } elseif ($page === $this->next_page_num) {
100
- $link .= "class='lcp_nextlink'";
101
  }
102
  $link .= ">";
103
  ($char != null) ? ($link .= $char) : ($link .= $page);
27
  return !empty($pagination) &&
28
  $pagination == 'yes' ||
29
  (get_option('lcp_pagination') === 'true' &&
30
+ ($pagination !== 'false')
 
31
  );
32
  }
33
 
94
  "#lcp_instance_" . $lcp_instance;
95
  $link .= "<li><a href='$page_link' title='$page'";
96
  if ($page === $this->prev_page_num) {
97
+ $link .= " class='lcp_prevlink'";
98
  } elseif ($page === $this->next_page_num) {
99
+ $link .= " class='lcp_nextlink'";
100
  }
101
  $link .= ">";
102
  ($char != null) ? ($link .= $char) : ($link .= $page);
include/lcp-parameters.php CHANGED
@@ -19,6 +19,7 @@ class LcpParameters{
19
 
20
  public function get_query_params($params){
21
  $this->params = $params;
 
22
  # Essential parameters:
23
  $args = array(
24
  'numberposts' => $params['numberposts'],
@@ -45,21 +46,9 @@ class LcpParameters{
45
  // Check type, status, parent params
46
  $args = $this->lcp_types_and_statuses($args);
47
 
48
- if($this->utils->lcp_not_empty('year')):
49
- $args['year'] = $params['year'];
50
- endif;
51
-
52
- if($this->utils->lcp_not_empty('monthnum')):
53
- $args['monthnum'] = $params['monthnum'];
54
- endif;
55
-
56
- if($this->utils->lcp_not_empty('search')):
57
- $args['s'] = $params['search'];
58
- endif;
59
-
60
- if($this->utils->lcp_not_empty('author_posts')):
61
- $args['author_name'] = $params['author_posts'];
62
- endif;
63
 
64
  // Posts within given date range:
65
  if ( $this->utils->lcp_not_empty('after') ) {
@@ -124,8 +113,10 @@ class LcpParameters{
124
  * should both be defined
125
  */
126
  if( $this->utils->lcp_not_empty('customfield_name') ){
127
- $args['meta_key'] = $params['customfield_name'];
128
- $args['meta_value'] = $params['customfield_value'];
 
 
129
  }
130
 
131
  //Get private posts
@@ -168,31 +159,8 @@ class LcpParameters{
168
  ));
169
  }
170
 
171
- // Multiple taxonomies support in the form
172
- // taxonomies_or="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
173
- // taxonomies_and="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
174
- if ( $this->utils->lcp_not_empty('taxonomies_or') || $this->utils->lcp_not_empty('taxonomies_and') ) {
175
- if($this->utils->lcp_not_empty('taxonomies_or')) {
176
- $operator = "OR";
177
- $taxonomies = $params['taxonomies_or'];
178
- } else {
179
- $operator = "AND";
180
- $taxonomies = $params['taxonomies_and'];
181
- }
182
- $count = preg_match_all('/([^:]+):\{([^:]+)\}(?:;|$)/im', $taxonomies, $matches, PREG_SET_ORDER, 0);
183
- if($count > 0) {
184
- $tax_arr = array('relation' => $operator);
185
- foreach ($matches as $match) {
186
- $tax_term = array(
187
- 'taxonomy' => $match[1],
188
- 'field' => 'slug',
189
- 'terms' => explode(",",$match[2])
190
- );
191
- array_push($tax_arr,$tax_term);
192
- }
193
- $args['tax_query'] = $tax_arr;
194
- }
195
- }
196
 
197
  // Tag support
198
  if ( $this->utils->lcp_not_empty('tags') ) {
@@ -204,8 +172,17 @@ class LcpParameters{
204
  }
205
 
206
  if ( $this->utils->lcp_not_empty('customfield_orderby') ){
207
- $args['orderby'] = 'meta_value';
208
- $args['meta_key'] = $params['customfield_orderby'];
 
 
 
 
 
 
 
 
 
209
  }
210
 
211
  // Posts that start with a given letter:
@@ -217,6 +194,16 @@ class LcpParameters{
217
  return $args;
218
  }
219
 
 
 
 
 
 
 
 
 
 
 
220
  // Check posts to exclude
221
  private function lcp_check_excludes($args){
222
  if( $this->utils->lcp_not_empty('excludeposts') ){
@@ -234,6 +221,36 @@ class LcpParameters{
234
  return $args;
235
  }
236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  private function lcp_types_and_statuses($args){
238
  // Post type, status, parent params:
239
  if($this->utils->lcp_not_empty('post_type')):
19
 
20
  public function get_query_params($params){
21
  $this->params = $params;
22
+ $meta_query = array();
23
  # Essential parameters:
24
  $args = array(
25
  'numberposts' => $params['numberposts'],
46
  // Check type, status, parent params
47
  $args = $this->lcp_types_and_statuses($args);
48
 
49
+ // Parameters which need to be checked simply, if they exist, add them to
50
+ // final return array ($args)
51
+ $args = $this->lcp_check_basic_params($args);
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  // Posts within given date range:
54
  if ( $this->utils->lcp_not_empty('after') ) {
113
  * should both be defined
114
  */
115
  if( $this->utils->lcp_not_empty('customfield_name') ){
116
+ $meta_query['select_clause'] = array(
117
+ 'key' => $params['customfield_name'],
118
+ 'value' => $params['customfield_value']
119
+ );
120
  }
121
 
122
  //Get private posts
159
  ));
160
  }
161
 
162
+ // Multiple taxonomies support
163
+ $args = $this->lcp_taxonomies($args);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  // Tag support
166
  if ( $this->utils->lcp_not_empty('tags') ) {
172
  }
173
 
174
  if ( $this->utils->lcp_not_empty('customfield_orderby') ){
175
+ $meta_query['orderby_clause'] = array(
176
+ 'key' => $params['customfield_orderby'],
177
+ 'compare' => 'EXISTS',
178
+ );
179
+ $args['orderby'] = 'orderby_clause';
180
+ }
181
+
182
+ // If either select_clause or orderby_clause were added to $meta_query,
183
+ // it needs to be added to args.
184
+ if ( !empty($meta_query) ) {
185
+ $args['meta_query'] = $meta_query;
186
  }
187
 
188
  // Posts that start with a given letter:
194
  return $args;
195
  }
196
 
197
+ private function lcp_check_basic_params($args){
198
+ $simple_args = array('year', 'monthnum', 'search', 'author_posts', 'after');
199
+ foreach($simple_args as $key){
200
+ if($this->utils->lcp_not_empty($key)){
201
+ $args[$key] = $this->params[$key];
202
+ }
203
+ }
204
+ return $args;
205
+ }
206
+
207
  // Check posts to exclude
208
  private function lcp_check_excludes($args){
209
  if( $this->utils->lcp_not_empty('excludeposts') ){
221
  return $args;
222
  }
223
 
224
+ private function lcp_taxonomies($args){
225
+ // Multiple taxonomies support in the form
226
+ // taxonomies_or="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
227
+ // taxonomies_and="tax1:{term1_1,term1_2};tax2:{term2_1,term2_2,term2_3}"
228
+ if ( $this->utils->lcp_not_empty('taxonomies_or') ||
229
+ $this->utils->lcp_not_empty('taxonomies_and') ) {
230
+ if($this->utils->lcp_not_empty('taxonomies_or')) {
231
+ $operator = "OR";
232
+ $taxonomies = $this->params['taxonomies_or'];
233
+ } else {
234
+ $operator = "AND";
235
+ $taxonomies = $this->params['taxonomies_and'];
236
+ }
237
+ $count = preg_match_all('/([^:]+):\{([^:]+)\}(?:;|$)/im', $taxonomies, $matches, PREG_SET_ORDER, 0);
238
+ if($count > 0) {
239
+ $tax_arr = array('relation' => $operator);
240
+ foreach ($matches as $match) {
241
+ $tax_term = array(
242
+ 'taxonomy' => $match[1],
243
+ 'field' => 'slug',
244
+ 'terms' => explode(",",$match[2])
245
+ );
246
+ array_push($tax_arr, $tax_term);
247
+ }
248
+ $args['tax_query'] = $tax_arr;
249
+ }
250
+ }
251
+ return $args;
252
+ }
253
+
254
  private function lcp_types_and_statuses($args){
255
  // Post type, status, parent params:
256
  if($this->utils->lcp_not_empty('post_type')):
include/lcp-widget-form.php CHANGED
@@ -67,7 +67,7 @@
67
  <br/>
68
  <select id="<?php echo $this->get_field_id('categoryid'); ?>" name="<?php echo $this->get_field_name('categoryid'); ?>">
69
  <?php
70
- $categories= get_categories();
71
  $option = '<option value="-1"';
72
  if ($categoryid == -1) :
73
  $option .= ' selected = "selected" ';
67
  <br/>
68
  <select id="<?php echo $this->get_field_id('categoryid'); ?>" name="<?php echo $this->get_field_name('categoryid'); ?>">
69
  <?php
70
+ $categories= get_categories(array('hide_empty' => false));
71
  $option = '<option value="-1"';
72
  if ($categoryid == -1) :
73
  $option .= ' selected = "selected" ';
list-category-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
- Version: 0.74.2
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
+ Version: 0.75
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.9
7
  Requires PHP: 5.2.4
8
- Stable tag: 0.74.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -44,7 +44,7 @@ Since WordPress 4.9, [you can use shortcode in text widgets](https://make.wordpr
44
 
45
  The plugin also includes a widget as a simple interface for its functionality. Just add as many widgets as you want, and select all the available options from the Appearence > Widgets page. Not all the functionality in the shortcode has been implemented in the widget yet. You can use the shortcode for the most flexibility.
46
 
47
- Please, read the information on [the wiki](https://github.com/picandocodigo/List-Category-Posts/wiki) and [Changelog](http://wordpress.org/extend/plugins/list-category-posts/changelog/) to be aware of new functionality, and improvements to the plugin.
48
 
49
  **Videos**
50
 
@@ -151,11 +151,11 @@ When using List Category Posts whithout a category id, name or slug, it will pos
151
  * **post_parent** - Show only the children of the post with this ID.
152
  Default: None.
153
 
154
- * **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. `customfield_name` defines the name of the field, and you should choose the values for which you want posts to display. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work. Eg: `[catlist customfield_name="color" customfield_value="green"]` will display posts with the value `green` set on the custom field `color`.
155
 
156
  ==PAGINATION
157
 
158
- https://github.com/picandocodigo/List-Category-Posts/wiki/Pagination
159
 
160
  ==OTHER PARAMETERS==
161
 
@@ -187,7 +187,7 @@ https://github.com/picandocodigo/List-Category-Posts/wiki/Pagination
187
  * **title** - Sort by title.
188
  * **type** - Sort by type. Ex: `[catlist name=mycategory orderby=date]`
189
 
190
- * **customfield_orderby** - You can order the posts by a custom field. For example: `[catlist numberposts=-1 customfield_orderby=Mood order=desc]` will list all the posts with a "Mood" custom field. Remember the default order is descending, more on order:
191
 
192
  * **order** - How to sort **orderby**. Valid values are:
193
  * **ASC** - Ascending (lowest to highest).
@@ -440,6 +440,14 @@ Template system has changed. Custom templates should be stored in WordPress them
440
 
441
  == Changelog ==
442
 
 
 
 
 
 
 
 
 
443
  = 0.74.2 =
444
 
445
  * Add pagination function for templates.
5
  Requires at least: 3.3
6
  Tested up to: 4.9
7
  Requires PHP: 5.2.4
8
+ Stable tag: 0.75
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
44
 
45
  The plugin also includes a widget as a simple interface for its functionality. Just add as many widgets as you want, and select all the available options from the Appearence > Widgets page. Not all the functionality in the shortcode has been implemented in the widget yet. You can use the shortcode for the most flexibility.
46
 
47
+ Please, read the information on [the wiki](https://github.com/picandocodigo/List-Category-Posts/wiki) and [Changelog](https://wordpress.org/plugins/list-category-posts/#developers) to be aware of new functionality, and improvements to the plugin.
48
 
49
  **Videos**
50
 
151
  * **post_parent** - Show only the children of the post with this ID.
152
  Default: None.
153
 
154
+ * **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. `customfield_name` defines the name of the field, and you should choose the values for which you want posts to display. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work. Eg: `[catlist customfield_name="color" customfield_value="green"]` will display posts with the value `green` set on the custom field `color`. This parameter can be used together with `customfield_orderby`, see further below for more information.
155
 
156
  ==PAGINATION
157
 
158
+ See the wiki: [Pagination](https://github.com/picandocodigo/List-Category-Posts/wiki/Pagination).
159
 
160
  ==OTHER PARAMETERS==
161
 
187
  * **title** - Sort by title.
188
  * **type** - Sort by type. Ex: `[catlist name=mycategory orderby=date]`
189
 
190
+ * **customfield_orderby** - You can order the posts by a custom field. For example: `[catlist numberposts=-1 customfield_orderby=Mood order=desc]` will list all the posts with a "Mood" custom field. This parameter can be used toghether with `customfield_name` and `customfield_value`, you can use those parameters to select posts and then `customfield_orderby` to sort by this or another custom field. Remember the default order is descending, more on order:
191
 
192
  * **order** - How to sort **orderby**. Valid values are:
193
  * **ASC** - Ascending (lowest to highest).
440
 
441
  == Changelog ==
442
 
443
+ = 0.75 =
444
+
445
+ * Improvements to `custom_fields` and `customfield_orderby`. Please check the readme for more information.
446
+ * Several bug fixes to pagination.
447
+ * Do not hide empty categories from widget.
448
+ Special thanks to Klemens Starybrat (zymeth25) for all the contributions.
449
+
450
+
451
  = 0.74.2 =
452
 
453
  * Add pagination function for templates.