List category posts - Version 0.87

Version Description

  • New feature: use keep_orderby_filters=yes to prevent the plugin from removing 'posts_orderby' filters added by other plugins/themes.
  • New feature: use ignore_sticky_posts=yes to ignore all sticky posts, they will still be displayed as regular posts in normal order if they match your filtering options, though. (#342)
  • New feature: use cat_sticky_posts=yes to make sticky posts 'stick' when filtering by category. (#423)
Download this release

Release Info

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

Code changes from version 0.86.1 to 0.87

include/lcp-catlist.php CHANGED
@@ -88,6 +88,8 @@ 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
  if ('no' === $this->params['main_query']) {
92
  // Use a standard Loop with WP_Query.
93
  $lcp_query = new WP_Query($args);
@@ -99,7 +101,9 @@ class CatList{
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;
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
+ do_action( 'lcp_pre_run_query', $args );
92
+
93
  if ('no' === $this->params['main_query']) {
94
  // Use a standard Loop with WP_Query.
95
  $lcp_query = new WP_Query($args);
101
  }
102
  $this->posts_count = $lcp_query->found_posts;
103
 
104
+ if ( $this->params[ 'keep_orderby_filters' ] !== 'yes' ) {
105
+ remove_all_filters('posts_orderby');
106
+ }
107
  remove_filter('posts_where', array(LcpParameters::get_instance(), 'starting_with'));
108
 
109
  return $lcp_query;
include/lcp-catlistdisplayer.php CHANGED
@@ -38,6 +38,9 @@ class CatListDisplayer {
38
  wp_reset_query();
39
  }
40
 
 
 
 
41
  return $this->lcp_output;
42
  }
43
 
38
  wp_reset_query();
39
  }
40
 
41
+ // This filter needs to be removed after template code has executed, not before.
42
+ remove_filter( 'the_posts', [ LcpParameters::get_instance(), 'move_sticky_to_top' ] );
43
+
44
  return $this->lcp_output;
45
  }
46
 
include/lcp-parameters.php CHANGED
@@ -9,6 +9,7 @@ class LcpParameters{
9
  private $starting_with = null;
10
  private $utils;
11
  private $params;
 
12
 
13
  // Use Trait for before/after date queries:
14
  use LcpDateQuery;
@@ -147,9 +148,38 @@ class LcpParameters{
147
  add_filter('posts_where' , array( $this, 'starting_with') );
148
  }
149
 
 
 
 
 
 
 
 
 
 
 
150
  return $args;
151
  }
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  private function lcp_check_basic_params($args){
154
  $simple_args = array('year', 'monthnum', 'after');
155
  foreach($simple_args as $key){
9
  private $starting_with = null;
10
  private $utils;
11
  private $params;
12
+ private $cat_sticky_posts;
13
 
14
  // Use Trait for before/after date queries:
15
  use LcpDateQuery;
148
  add_filter('posts_where' , array( $this, 'starting_with') );
149
  }
150
 
151
+ // Post stickiness
152
+ if ( 'yes' === $params['ignore_sticky_posts'] ) {
153
+ $args['ignore_sticky_posts'] = true;
154
+ }
155
+
156
+ if ( $params[ 'cat_sticky_posts' ] === 'yes' ) {
157
+ add_action( 'lcp_pre_run_query', [ $this, 'get_cat_sticky_posts' ] );
158
+ add_filter( 'the_posts', [ $this, 'move_sticky_to_top' ] );
159
+ }
160
+
161
  return $args;
162
  }
163
 
164
+ public function get_cat_sticky_posts( $args ) {
165
+ $sticky_ids = get_option( 'sticky_posts' );
166
+ $sticky_query = new WP_Query(
167
+ array_merge( $args, [ 'post__in' => $sticky_ids ] )
168
+ );
169
+ $this->cat_sticky_posts = $sticky_query->posts;
170
+ }
171
+
172
+ public function move_sticky_to_top( $posts ) {
173
+ remove_action( 'lcp_pre_run_query', [ $this, 'get_cat_sticky_posts' ] );
174
+ if ( null == $this->cat_sticky_posts ) return $posts;
175
+
176
+ $newposts = array_merge( $this->cat_sticky_posts, $posts );
177
+
178
+ $this->cat_sticky_posts = null;
179
+
180
+ return $newposts;
181
+ }
182
+
183
  private function lcp_check_basic_params($args){
184
  $simple_args = array('year', 'monthnum', 'after');
185
  foreach($simple_args as $key){
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.86.1
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
@@ -166,6 +166,9 @@ class ListCategoryPosts{
166
  'pagination_bookmarks' => '',
167
  'ol_offset' => '',
168
  'main_query' => '',
 
 
 
169
  );
170
  }
171
  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.87
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
166
  'pagination_bookmarks' => '',
167
  'ol_offset' => '',
168
  'main_query' => '',
169
+ 'keep_orderby_filters' => '',
170
+ 'ignore_sticky_posts' => '',
171
+ 'cat_sticky_posts' => '',
172
  );
173
  }
174
  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.9
7
  Requires PHP: 5.4
8
- Stable tag: 0.86.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -237,6 +237,12 @@ Template system has changed. Custom templates should be stored in WordPress them
237
 
238
  == Changelog ==
239
 
 
 
 
 
 
 
240
  = 0.86.1 =
241
 
242
  * Fixed multiple CSS classes, things like `[catlist posts_cats=yes posts_cats_class="feed categories"]` now work.
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: 6.0
7
  Requires PHP: 5.4
8
+ Stable tag: 0.87
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
237
 
238
  == Changelog ==
239
 
240
+ = 0.87 =
241
+
242
+ * **New feature**: use `keep_orderby_filters=yes` to prevent the plugin from removing 'posts_orderby' filters added by other plugins/themes.
243
+ * **New feature**: use `ignore_sticky_posts=yes` to ignore all sticky posts, they will still be displayed as regular posts in normal order if they match your filtering options, though. (#342)
244
+ * **New feature**: use `cat_sticky_posts=yes` to make sticky posts 'stick' when filtering by category. (#423)
245
+
246
  = 0.86.1 =
247
 
248
  * Fixed multiple CSS classes, things like `[catlist posts_cats=yes posts_cats_class="feed categories"]` now work.