Title: Detecting current tags
Last modified: August 21, 2016

---

# Detecting current tags

 *  [Sofian777](https://wordpress.org/support/users/sofian777/)
 * (@sofian777)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/)
 * Hello, we would like to output a recommendations list in the sidebar that is 
   based on the tags of the current post. So lets say the post has tag1 tag2 and
   tag3, we want to output 3 random posts of all posts that also have tag1 or tag2
   or tag3. I discovered the categorypage parameter that detects the current category.
   Is there any possibility to also detect the currents tags?
 * [https://wordpress.org/plugins/list-category-posts/](https://wordpress.org/plugins/list-category-posts/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Fernando Briano](https://wordpress.org/support/users/fernandobt/)
 * (@fernandobt)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591320)
 * Adding this to version 0.44 too, check it out!
 *  Thread Starter [Sofian777](https://wordpress.org/support/users/sofian777/)
 * (@sofian777)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591323)
 * but, please tell me, did you write it now after my posts because you liked the
   idea, or is it such a syncronicity that you worked on exaxtly the two options
   i need right now?
 * if option 1, then thank you for your amazing fast response and integration of
   the parameters.
 * i will check it out soon, at latest tomorrow i will give you feedback…
 * _sidenote:
    [http://wordpress.org/plugins/list-category-posts/other\_notes/](http://wordpress.org/plugins/list-category-posts/other_notes/)
   there is one star too much, giving wrong formatting: **currenttags*
 *  Thread Starter [Sofian777](https://wordpress.org/support/users/sofian777/)
 * (@sofian777)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591326)
 * First test:
 * I added `[catlist currenttags=yes]` into a text widget and it seems that it works
   on a AND base, so only the posts that have exactly all the same tags are shown(
   in my case only the same post 🙂 I guess this is more rarely needed.
 * I would need it on a OR base, meaning it is enough if one of the tags of two 
   posts are the same to be taken into the list. Is this possible as well? I think
   this behaviour would make more sense in general for most situations.
 * On pages, the widget gives an error message (of course it should not be displayed
   on pages with such a function, since they have no tags, but maybe it can just
   stay empty)
 * `Warning: Invalid argument supplied for foreach() in /var/www/vhosts/sundari-
   spiritual-art.de/httpdocs/imlichtewplay/wp-content/plugins/list-category-posts/
   include/CatList.php on line 241`
 *  Thread Starter [Sofian777](https://wordpress.org/support/users/sofian777/)
 * (@sofian777)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591367)
 * Hello again, i saw you already fixed the error message in a new update. Could
   you please let me know about the AND / OR fact, just a short line if you consider
   to add/change it, thank you once more…
 *  Plugin Author [Fernando Briano](https://wordpress.org/support/users/fernandobt/)
 * (@fernandobt)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591417)
 * Hi Sofian777,
    Yep got the warning fixed.
 * About the other question, [I am using the tag__in parameter](https://github.com/picandocodigo/List-Category-Posts/blob/master/include/CatList.php#L125)
   from [WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters).
   So it should be using (it is in my tests) the OR relationship. To use an AND 
   relationship, I should use the `tag__and` parameter.
 * How are you using it on the text widget? Just the shortcode and it works?
 * It’s really strange :S
    Double check your tags and let me know, see if we can
   fix this.
 * Thanks!
 *  Thread Starter [Sofian777](https://wordpress.org/support/users/sofian777/)
 * (@sofian777)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591439)
 * The shortcode didnt simply work, i added
    `add_filter('widget_text', 'do_shortcode');`
   to my functions.php 😉
 * I made now more detailed testing and it is true, it works after the AND principle,
   the mistake was in our tag structure that made it look different. With specific
   testposts i can now confirm AND.
 * Yet i discovered
 * – one unclear behaviour:
    When the post has no tag, or a page is opened (which
   has no tags by nature), the error message is fixed, but the list is not empty,
   but full, it seems to take “nothing” for “everything”. Maybe a little “if posthavetag”
   or something could avoid this. I think if there is no match, it needs to be empty.
 * – one improvement:
    the post itself is also listed, which i think in rare cases
   is wanted or needed. can it be excluded?
 *  Thread Starter [Sofian777](https://wordpress.org/support/users/sofian777/)
 * (@sofian777)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591466)
 * I just read another post now:
    [http://wordpress.org/support/topic/remove-current-post-from-list](http://wordpress.org/support/topic/remove-current-post-from-list)
   which solves my last point here.
 *  Plugin Author [Fernando Briano](https://wordpress.org/support/users/fernandobt/)
 * (@fernandobt)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591491)
 * I’ll add a condition for when there are no tags to not show any posts. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Detecting current tags’ is closed to new replies.

 * ![](https://ps.w.org/list-category-posts/assets/icon-256x256.png?rev=2517221)
 * [List category posts](https://wordpress.org/plugins/list-category-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/list-category-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/list-category-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/list-category-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/list-category-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/list-category-posts/reviews/)

## Tags

 * [detect](https://wordpress.org/support/topic-tag/detect/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)

 * 8 replies
 * 2 participants
 * Last reply from: [Fernando Briano](https://wordpress.org/support/users/fernandobt/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/detecting-current-tags/#post-4591491)
 * Status: not resolved