List category posts - Version 0.85

Version Description

  • New feature: Support for custom field data types for customfield_orderby, use customfield_orderby_type. Thanks @vosykapavel!
  • New feature: Run LCP in standard secondary loop mode with main_query=no. See the docs and #445.
  • Removed the target attribute from <a> elements in post titles (#464) .
  • post_parent=0 post_type=page now works as expected, displaying only top level pages (#370).
  • Fixed multiple authors by id (#426).
Download this release

Release Info

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

Code changes from version 0.84.2 to 0.85

include/lcp-catlist.php CHANGED
@@ -43,7 +43,7 @@ class CatList{
43
  * Determine the categories of posts and execute the WP_query
44
  */
45
  public function get_posts() {
46
- $this->set_lcp_parameters();
47
  }
48
 
49
  /**
@@ -88,11 +88,21 @@ class CatList{
88
  // http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
89
  $args['posts_per_page'] = $args['numberposts'];
90
 
91
- query_posts($args);
92
- global $wp_query;
93
- $this->posts_count = $wp_query->found_posts;
 
 
 
 
 
 
 
 
94
  remove_all_filters('posts_orderby');
95
  remove_filter('posts_where', array(LcpParameters::get_instance(), 'starting_with'));
 
 
96
  }
97
 
98
  /* Should I return posts or show that the tag/category or whatever
43
  * Determine the categories of posts and execute the WP_query
44
  */
45
  public function get_posts() {
46
+ return $this->set_lcp_parameters();
47
  }
48
 
49
  /**
88
  // http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
89
  $args['posts_per_page'] = $args['numberposts'];
90
 
91
+ if ('no' === $this->params['main_query']) {
92
+ // Use a standard Loop with WP_Query.
93
+ $lcp_query = new WP_Query($args);
94
+ } else {
95
+ // Run as a main query.
96
+ query_posts($args);
97
+ global $wp_query;
98
+ $lcp_query = $wp_query;
99
+ }
100
+ $this->posts_count = $lcp_query->found_posts;
101
+
102
  remove_all_filters('posts_orderby');
103
  remove_filter('posts_where', array(LcpParameters::get_instance(), 'starting_with'));
104
+
105
+ return $lcp_query;
106
  }
107
 
108
  /* Should I return posts or show that the tag/category or whatever
include/lcp-catlistdisplayer.php CHANGED
@@ -14,6 +14,7 @@ class CatListDisplayer {
14
  private $templater;
15
  private $params = array();
16
  private $lcp_output;
 
17
 
18
  public function __construct($atts) {
19
  $this->params = $atts;
@@ -25,11 +26,18 @@ class CatListDisplayer {
25
  }
26
 
27
  public function display(){
28
- $this->catlist->save_wp_query();
29
- $this->catlist->get_posts();
30
- $this->create_output();
31
- $this->catlist->restore_wp_query();
32
- wp_reset_query();
 
 
 
 
 
 
 
33
  return $this->lcp_output;
34
  }
35
 
@@ -213,8 +221,6 @@ class CatListDisplayer {
213
  $props['target'] = $this->params['link_target'];
214
  }
215
 
216
- $props['title'] = wptexturize($single->post_title);
217
-
218
  $output = $this->wrapper->to_html('a', $props, $text);
219
 
220
  if ($single->post_status == 'private') {
14
  private $templater;
15
  private $params = array();
16
  private $lcp_output;
17
+ private $lcp_query;
18
 
19
  public function __construct($atts) {
20
  $this->params = $atts;
26
  }
27
 
28
  public function display(){
29
+ if ('no' === $this->params['main_query']) {
30
+ $this->lcp_query = $this->catlist->get_posts();
31
+ $this->create_output();
32
+ wp_reset_postdata();
33
+ } else {
34
+ $this->catlist->save_wp_query();
35
+ $this->lcp_query = $this->catlist->get_posts();
36
+ $this->create_output();
37
+ $this->catlist->restore_wp_query();
38
+ wp_reset_query();
39
+ }
40
+
41
  return $this->lcp_output;
42
  }
43
 
221
  $props['target'] = $this->params['link_target'];
222
  }
223
 
 
 
224
  $output = $this->wrapper->to_html('a', $props, $text);
225
 
226
  if ($single->post_status == 'private') {
include/lcp-meta-query.php CHANGED
@@ -87,6 +87,10 @@ trait LcpMetaQuery {
87
  'key' => $params['customfield_orderby'],
88
  'compare' => 'EXISTS',
89
  );
 
 
 
 
90
  }
91
  }
92
 
87
  'key' => $params['customfield_orderby'],
88
  'compare' => 'EXISTS',
89
  );
90
+
91
+ if( !empty($params['customfield_orderby_type']) ) {
92
+ $meta_query['orderby_clause']['type'] = strtoupper($params['customfield_orderby_type']);
93
+ }
94
  }
95
  }
96
 
include/lcp-parameters.php CHANGED
@@ -54,8 +54,8 @@ class LcpParameters{
54
  if ($authors == 'current_user'){
55
  $args['author'] = wp_get_current_user()->ID;
56
  } else {
57
- if(preg_match('/,/', $authors)){
58
- $args['author__in'] = $authors;
59
  } else {
60
  $args['author_name'] = $authors;
61
  }
@@ -212,7 +212,7 @@ class LcpParameters{
212
  $args['post_status'] = explode( ',', $this->params['post_status'] );
213
  endif;
214
 
215
- if($this->utils->lcp_not_empty('post_parent')):
216
  $args['post_parent'] = $this->params['post_parent'];
217
  endif;
218
  return $args;
54
  if ($authors == 'current_user'){
55
  $args['author'] = wp_get_current_user()->ID;
56
  } else {
57
+ if( false !== strpos($authors,',')){
58
+ $args['author'] = $authors;
59
  } else {
60
  $args['author_name'] = $authors;
61
  }
212
  $args['post_status'] = explode( ',', $this->params['post_status'] );
213
  endif;
214
 
215
+ if( '' !== $this->params[ 'post_parent' ] ):
216
  $args['post_parent'] = $this->params['post_parent'];
217
  endif;
218
  return $args;
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.84.2
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
@@ -93,7 +93,7 @@ class ListCategoryPosts{
93
  'title_limit' => '0',
94
  'post_type' => '',
95
  'post_status' => '',
96
- 'post_parent' => '0',
97
  'post_suffix' => '',
98
  'show_protected' => 'no',
99
  'class' => '',
@@ -107,7 +107,8 @@ class ListCategoryPosts{
107
  'customfield_display_name' =>'',
108
  'customfield_display_name_glue' => ' : ',
109
  'customfield_display_separately' => 'no',
110
- 'customfield_orderby' =>'',
 
111
  'customfield_tag' => '',
112
  'customfield_class' => '',
113
  'customfield_compare' => '',
@@ -148,7 +149,8 @@ class ListCategoryPosts{
148
  'before_day' => '',
149
  'tags_as_class' => 'no',
150
  'pagination_bookmarks' => '',
151
- 'ol_offset' => ''
 
152
  );
153
  }
154
  return self::$default_params;
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.85
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
93
  'title_limit' => '0',
94
  'post_type' => '',
95
  'post_status' => '',
96
+ 'post_parent' => '',
97
  'post_suffix' => '',
98
  'show_protected' => 'no',
99
  'class' => '',
107
  'customfield_display_name' =>'',
108
  'customfield_display_name_glue' => ' : ',
109
  'customfield_display_separately' => 'no',
110
+ 'customfield_orderby' => '',
111
+ 'customfield_orderby_type' => '',
112
  'customfield_tag' => '',
113
  'customfield_class' => '',
114
  'customfield_compare' => '',
149
  'before_day' => '',
150
  'tags_as_class' => 'no',
151
  'pagination_bookmarks' => '',
152
+ 'ol_offset' => '',
153
+ 'main_query' => '',
154
  );
155
  }
156
  return self::$default_params;
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: fernandobt, zymeth25
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
- Tested up to: 5.7.1
7
  Requires PHP: 5.4
8
- Stable tag: 0.84.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -237,6 +237,14 @@ Template system has changed. Custom templates should be stored in WordPress them
237
 
238
  == Changelog ==
239
 
 
 
 
 
 
 
 
 
240
  = 0.84.2 =
241
 
242
  * Fixed includeposts undefined index in older widgets.
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
+ Tested up to: 5.8
7
  Requires PHP: 5.4
8
+ Stable tag: 0.85
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
237
 
238
  == Changelog ==
239
 
240
+ = 0.85 =
241
+
242
+ * **New feature**: Support for custom field data types for `customfield_orderby`, use `customfield_orderby_type`. Thanks @vosykapavel!
243
+ * **New feature**: Run LCP in standard secondary loop mode with `main_query=no`. See [the docs](https://github.com/picandocodigo/List-Category-Posts/wiki/More-parameters-you-can-use#other-parameters) and #445.
244
+ * Removed the `target` attribute from `<a>` elements in post titles (#464) .
245
+ * `post_parent=0 post_type=page` now works as expected, displaying only top level pages (#370).
246
+ * Fixed multiple authors by id (#426).
247
+
248
  = 0.84.2 =
249
 
250
  * Fixed includeposts undefined index in older widgets.
templates/default.php CHANGED
@@ -59,10 +59,13 @@ $lcp_display_output .= $this->open_outer_tag('ul', 'lcp_catlist');
59
  * you'll see get_excerpt, get_thumbnail, etc. You can now pass an
60
  * html tag as a parameter. This tag will sorround the info you want
61
  * to display. You can also assign a specific CSS class to each field.
 
 
 
62
  */
63
  global $post;
64
- while ( have_posts() ):
65
- the_post();
66
 
67
  // Check if protected post should be displayed
68
  if (!$this->check_show_protected($post)) continue;
59
  * you'll see get_excerpt, get_thumbnail, etc. You can now pass an
60
  * html tag as a parameter. This tag will sorround the info you want
61
  * to display. You can also assign a specific CSS class to each field.
62
+ *
63
+ * IMPORTANT: Prior to v0.85 lines 65-67 were different. Make sure your
64
+ * template is up to date.
65
  */
66
  global $post;
67
+ while ( $this->lcp_query->have_posts() ):
68
+ $this->lcp_query->the_post();
69
 
70
  // Check if protected post should be displayed
71
  if (!$this->check_show_protected($post)) continue;