WordPress.org

Ready to get started?Download WordPress

Forums

List category posts
support for boolean-and? (13 posts)

  1. dnorman
    Member
    Posted 3 years ago #

    When passing a list of category IDs to the plugin, it uses the boolean-or query, so posts in any of the categories get returned - but this plugin gets even more useful when modified to support boolean-and, so that only posts in all of the listed categories are returned.

    I've hacked this into my copy of the plugin, but am not sure how to implement it properly (so that it doesn't break expected behaviour for people relying on the existing boolean-or functionality).

    The boolean-and query is baked into WordPress now, but the query needs to be modified to support it.

    Here's the modifed query I use, in list_category_posts():

    $catposts = get_posts(array(
    	'category__and'=>explode(",", $atts['id']),
    	'posts_per_page'=>$atts['numberposts'],
    	'orderby'=>$atts['orderby'],
    	'order'=>$atts['order'],
    	));
  2. Jay Collier
    Member
    Posted 3 years ago #

    An AND/OR option would be a great addition to this plugin!

  3. Jay Collier
    Member
    Posted 3 years ago #

    Question. Does 'get_posts' allow 'category__and'? Or, do you mean 'query_posts'?

  4. dnorman
    Member
    Posted 3 years ago #

    I took a look at the docs for get_posts, and it appears to be able to accept the same args as query_posts. It just needs some tweaking (feeding an array of category IDs instead of a text string, etc...)

  5. Jay Collier
    Member
    Posted 3 years ago #

    Thank you for the update.

    I am finding that a boolean-and option is more and more significant as I am developing deep site architecture, yet few plugins include this option for categories, let alone custom post types.

    Your information will be helpful for other plugin developers, too. I've already fowarded this thread ...

  6. Jay Collier
    Member
    Posted 3 years ago #

    Dnorman, I used your code and it works great, with one change: I changed 'posts_per_page' to 'numberposts'.

    '$catposts = get_posts(array(
       'category__and'=>explode(",", $atts['id']),
       'numberposts'=>$atts['numberposts'],
       'orderby'=>$atts['orderby'],
       'order'=>$atts['order'],
       ));'

    Thank you!

  7. dnorman
    Member
    Posted 3 years ago #

    Cool! Glad to help :-)

  8. Jay Collier
    Member
    Posted 3 years ago #

    BTW, it's worth noting that category__add does not include child categories, whereas id and name do.

    I also tried initializing a new parameter name and applying it to category__add ('add' instead of 'id') and the result was always null.

    So, I came back around to your original question: how to support the boolean-or parameter 'id' and also add the boolean-and parameter.

    For the moment, this is such an important plugin and I always need category-name or boolean-and, so I'll ignore the boolean-or altogether.

  9. Jay Collier
    Member
    Posted 3 years ago #

    I see there has just been an update to this plugin.

    Hoping boolean-or will be integrated.

  10. fernandobt
    Member
    Plugin Author

    Posted 3 years ago #

    I hadn't even considered this feature, but I'll dig into it for a future version of the plugin.

    Thanks for your code and ideas, I'll take a look at the docs from WordPress and come up with a way to integrate this functionality. Any more feedback is welcome!

    Regards

  11. Jay Collier
    Member
    Posted 3 years ago #

    Thank you for considering this!

  12. spelverso
    Member
    Posted 3 years ago #

    Hi, thanks for your work. This is the best (useful) plugin I've ever downloaded.

    Jus a request. Could you add to it an option to choose not only "AND/OR" between 2/3/... categories, but also between 2/3/... tags and also between category and tags?
    In example: query posts from cat1 AND tag5.

  13. Jay Collier
    Member
    Posted 3 years ago #

    This is still one of the most important issues I've come across with WordPress, and since I use your plugin everywhere, I am hoping that you might be working on an AND/OR option, as mentioned by spelverso.

    BTW, this came up in an earlier thread:

    http://wordpress.org/support/topic/plugin-list-category-posts-list-posts-with-two-categories

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic