Skip to content

Commit f1f956d

Browse files
committed
Should fix issues with tags when using more than one tag for OR and AND relationships.
Documented the use of custom taxonomies. For some reason I never came around to do that. I changed the parameters for taxonomies, it used the 'tags' parameter for 'terms' before, so I added a 'terms' parameter to make this independent from the tags parameter. So now it looks like this: `[catlist taxonomy='person' terms='bob']`. This might break some current uses of taxonomy, but since it was written so long ago and I don't know why it used "tags", I decided to just create the 'terms' parameter. People using the custom taxonomies were people who are looking at the code anyway since I can't find it documented anywhere. Sorry for the inconveniences!
1 parent ba2ffa6 commit f1f956d

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

include/lcp-parameters.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ public function get_query_params($params){
7979
}
8080

8181
// Custom taxonomy support
82-
if ( $this->utils->lcp_not_empty('taxonomy') && $this->utils->lcp_not_empty('tags') ){
82+
// Why didn't I document this?!?
83+
if ( $this->utils->lcp_not_empty('taxonomy') && $this->utils->lcp_not_empty('terms') ){
8384
$args['tax_query'] = array(array(
8485
'taxonomy' => $params['taxonomy'],
8586
'field' => 'slug',
86-
'terms' => explode(",",$params['tags'])
87+
'terms' => explode(",",$params['terms'])
8788
));
88-
} elseif ( !empty($params['tags']) ) {
89+
}
90+
91+
// Tag support
92+
if ( $this->utils->lcp_not_empty('tags') ) {
8993
$args['tag'] = $params['tags'];
9094
}
9195

list-category-posts.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: List category posts
44
Plugin URI: https://github.com/picandocodigo/List-Category-Posts
55
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.65
6+
Version: 0.66
77
Author: Fernando Briano
88
Author URI: http://fernandobriano.com
99
@@ -109,6 +109,7 @@ static function catlist_func($atts, $content = null) {
109109
'customfield_tag' => '',
110110
'customfield_class' => '',
111111
'taxonomy' => '',
112+
'terms' => '',
112113
'categorypage' => '',
113114
'category_count' => '',
114115
'morelink' => '',

readme.txt

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts
44
Tags: list, categories, posts, cms
55
Requires at least: 3.3
66
Tested up to: 4.3.1
7-
Stable tag: 0.65
7+
Stable tag: 0.66
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -110,6 +110,54 @@ When using List Category Posts whithout a category id, name or slug, it will pos
110110
* Posts from several categories with an **OR** relationship, posts that belong to any of the listed categories: `[catlist id=17,24,32]` - `[catlist name=sega,nintendo]`.
111111
* **Exclude** a category with the minus sign (-): `[catlist id=11,-32,16]`, `[catlist id=1+2-3]`. **Important**: When using the *and* relationship, you should write the categories you want to include first, and then the ones you want to exclude. So `[catlist id=1+2-3]` will work, but `[catlist id=1+2-3+4]` won't.
112112

113+
==Other ways of selecting what posts to show==
114+
115+
* **author_posts** - Get posts by author. Use 'user_nicename' (NOT
116+
name). Example: `[catlist author_posts="fernando"]`
117+
118+
* **tags** - Tag support, display posts from a certain tag. You can use an "OR" relationship `[catlist tags="nintendo,sega"]` or "AND" relationship (posts that belong to all of the listed tags): `[catilst tags="nintendo+sega"]`.
119+
120+
* **taxonomy** - You can select posts using custom taxonomies. You need to set the taxonomy and the terms: `[catlist taxonomy='person' terms='bob']`.
121+
122+
* **currenttags** - Display posts from the current post's tags (won't
123+
work on pages since they have no tags). Pass it the 'yes' string for it to work: `[catlist currenttags="yes"]`
124+
125+
* **exclude_tags** - Exclude posts from one or more tags: `[catlist tags="videogames" exclude_tags="sega,sony"]`
126+
127+
* **starting_with** - Get posts whose title starts with a certain
128+
letter. Example: `[catlist starting_with="l"]` will list all posts
129+
whose title starts with L. You can use several letters: `[catlist starting_with="m,o,t"]`.
130+
131+
* **monthnum** and **year** - List posts from a certain year or month. You can use these together or independently. Example: `[catlist year=2015]` will list posts from the year 2015. `[catlist monthnum=8]` will list posts published in August of every year. `[catlist year=2012 monthnum=12]` will list posts from December 2012.
132+
133+
* **search** - List posts that match a search term. `[catlist search="The Cake is a lie"]`
134+
135+
* **excludeposts** - IDs of posts to exclude from the list. Use 'this' to exclude the current post. Ex: `[catlist excludeposts=this,12,52,37]`
136+
137+
* **offset** - You can displace or pass over one or more initial posts which would normally be collected by your query through the use of the offset parameter.
138+
139+
* **post_type** - The type of post to show. Available options are: post - Default, page, attachment, any - all post types. You can use several types, example: `[catlist post_type="page,post" numberposts=-1]`
140+
141+
* **post_status** - use post status, default value is 'publish'. Valid values:
142+
* **publish** - a published post or page.
143+
* **pending** - post is pending review.
144+
* **draft** - a post in draft status.
145+
* **auto-draft** - a newly created post, with no content.
146+
* **future** - a post to publish in the future.
147+
* **private** - not visible to users who are not logged in.
148+
* **inherit** - a revision. see get_children.
149+
* **trash** - post is in trashbin (available with Version 2.9).
150+
* **any** - retrieves any status except those from post types with 'exclude_from_search' set to true.
151+
You can use several post statuses. Example: `[catlist post_status="future, publish" excludeposts=this]`
152+
153+
* **show_protected** - Show posts protected by password. By default
154+
they are not displayed. Use: `[catlist show_protected=yes]`
155+
156+
* **post_parent** - Show only the children of the post with this ID.
157+
Default: None.
158+
159+
* **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work.
160+
113161
==PAGINATION==
114162

115163
To use pagination, you need to set the following parameters in the shortcode:
@@ -164,16 +212,6 @@ update the plugin.
164212
* **conditional_title_class** - Specify the class used for the conditional
165213
title. Defaults to the empty string (no special class).
166214

167-
* **author_posts** - Get posts by author. Use 'user_nicename' (NOT
168-
name). Example: `[catlist author_posts="fernando"]`
169-
170-
* **tags** - Tag support, display posts from a certain tag.
171-
172-
* **currenttags** - Display posts from the current post's tags (won't
173-
work on pages since they have no tags). Pass it the 'yes' string for it to work: `[catlist currenttags="yes"]`
174-
175-
* **exclude_tags** - Exclude posts from one or more tags: `[catlist tags="videogames" exclude_tags="sega,sony"]`
176-
177215
* **orderby** - To customize the order. Valid values are:
178216
* **author** - Sort by the numeric author IDs.
179217
* **category** - Sort by the numeric category IDs.
@@ -197,10 +235,6 @@ update the plugin.
197235
* **ASC** - Ascending (lowest to highest).
198236
* **DESC** - Descending (highest to lowest). Ex: `[catlist name=mycategory orderby=title order=asc]`
199237

200-
* **starting_with** - Get posts whose title starts with a certain
201-
letter. Example: `[catlist starting_with="l"]` will list all posts
202-
whose title starts with L. You can use several letters: `[catlist starting_with="m,o,t"]`.
203-
204238
* **numberposts** - Number of posts to return. Set to 0 to use the max
205239
number of posts per page. Set to -1 to remove the limit.
206240
Ex: `[catlist name=mycategory numberposts=10]`
@@ -211,10 +245,6 @@ update the plugin.
211245
don't specify it, nothing will get displayed where the posts
212246
should be.
213247

214-
* **monthnum** and **year** - List posts from a certain year or month. You can use these together or independently. Example: `[catlist year=2015]` will list posts from the year 2015. `[catlist monthnum=8]` will list posts published in August of every year. `[catlist year=2012 monthnum=12]` will list posts from December 2012.
215-
216-
* **search** - List posts that match a search term. `[catlist search="The Cake is a lie"]`
217-
218248
* **date** - Display post's date next to the title. Default is 'no',
219249
use date=yes to activate it. You can set a css class and an html
220250
tag to wrap the date in with `date_class` and `date_tag` (see HTML
@@ -255,10 +285,6 @@ update the plugin.
255285
`[catlist id=2 title_limit=50]` will show only the first 50
256286
characters of the title and add "…" at the end.
257287

258-
* **excludeposts** - IDs of posts to exclude from the list. Use 'this' to exclude the current post. Ex: `[catlist excludeposts=this,12,52,37]`
259-
260-
* **offset** - You can displace or pass over one or more initial posts which would normally be collected by your query through the use of the offset parameter.
261-
262288
* **content** - **WARNING**: If you want to show the content on your listed posts, you might want to do this from a new [Page Template](http://codex.wordpress.org/Page_Templates) or a [Custom Post Type](http://codex.wordpress.org/Post_Types#Custom_Post_Type_Templates) template. Using this parameter is discouraged, you can have memory issues as well as infinite loop situations when you're displaying a post that's using List Category Posts. You have been warned. Usage:
263289

264290
Show the excerpt or full content of the post. If there's a <!--more--> tag in the post, then it will behave just as WordPress does: only show the content previous to the more tag. Default is 'no'. Ex: `[catlist content=yes]`
@@ -279,26 +305,6 @@ Show the full content of the post regardless of whether there is a <!--more--
279305

280306
* **thumbnail_class** - Set a CSS class for the thumbnail.
281307

282-
* **post_type** - The type of post to show. Available options are: post - Default, page, attachment, any - all post types. You can use several types, example: `[catlist post_type="page,post" numberposts=-1]`
283-
284-
* **post_status** - use post status, default value is 'publish'. Valid values:
285-
* **publish** - a published post or page.
286-
* **pending** - post is pending review.
287-
* **draft** - a post in draft status.
288-
* **auto-draft** - a newly created post, with no content.
289-
* **future** - a post to publish in the future.
290-
* **private** - not visible to users who are not logged in.
291-
* **inherit** - a revision. see get_children.
292-
* **trash** - post is in trashbin (available with Version 2.9).
293-
* **any** - retrieves any status except those from post types with 'exclude_from_search' set to true.
294-
You can use several post statuses. Example: `[catlist post_status="future, publish" excludeposts=this]`
295-
296-
* **show_protected** - Show posts protected by password. By default
297-
they are not displayed. Use: `[catlist show_protected=yes]`
298-
299-
* **post_parent** - Show only the children of the post with this ID.
300-
Default: None.
301-
302308
* **post_suffix** - Pass a String to this parameter to display this
303309
String after every post title.
304310
Ex: `[catlist numberposts=-1
@@ -314,8 +320,6 @@ Show the full content of the post regardless of whether there is a <!--more--
314320

315321
* **class** - CSS class for the default UL generated by the plugin.
316322

317-
* **custom fields** - To use custom fields, you must specify two values: customfield_name and customfield_value. Using this only show posts that contain a custom field with this name and value. Both parameters must be defined, or neither will work.
318-
319323
* **customfield_display** - Display custom field(s). You can specify
320324
many fields to show, separating them with a coma. If you want to
321325
display just the value and not the name of the custom field, use

0 commit comments

Comments
 (0)