Le blog de Tester

Catégories

Amigos

Moi Tester

Planètes

Projets

Archives

mars 2005
D L Ma Me J V S
« jan   avr »
 12345
6789101112
13141516171819
20212223242526
2728293031  

RSS 2.0


Connexion

Intersect plugin

I decided to switch to WordPress so I could have categories in my blog and I could get RSS feeds on only one of them to be imported in different planets… But I had posts in both French and English in my Gentoo category. So I check if I could say « only take posts from category english and gentoo »… But if I select two categories, I get a union, not an intersection. So I wrote this little plugin. To have an intersection, you can do ?cat=x,y&intersect=1 … Example http://www.tester.ca/?cat=2,10&intersect=1 for my English & Gentoo posts. Also, this only works with category numbers.

File is here, dont forget to rename it .php to remove the .txt extension. Put in in wp-content/plugins/ and enable it..

Update: I just upgraded to 2.5 and I think it works as is. Please report any problems

Ce billet a été posté le 24 mars 2005 à 2:40 et est dans la catégorie English, Informatique.
Vous pouvez suivre les réponses avec le RSS 2.0. Vous pouvez laisser une réponse, ou un trackback sur votre propre site.

18 réponses à “Intersect plugin”

  1. Kenyon dit:

    You mean 2,10 of course.

  2. INF3300 dit:

    On attend toujours ton travail de INF3300 Olivier…

  3. Tester dit:

    Kenyon, of course, corrected, thanks ;)

  4. Jason Pearce dit:

    Thanks so much. I’ve been playing with several other plugins to get this functionality. As I’m sure you are aware, you can interset more than two categories; e.g. /?cat=2,10,15&intersect=1.

  5. Tester dit:

    yes yes.. you can intersect as many categories as you want…

  6. adeh dit:

    Hi, this is exactly what I needed. I made a small change though to use $wp_query->query_vars instead of $_GET because I am using wordpress more as a CMS, and embedding certian categories in certian pages.

  7. David Esrati dit:

    Has anyone used this plug-in with WP 2.0? And- what are the other plug-ins that Jason has tried?
    Thanks

  8. Tester dit:

    Hmm, I will port it to WP 2.0 when I move my blog over… I dont know when…

  9. David Esrati dit:

    Hi-
    Does anyone have a working example of this plug-in on their site? WP 1.5?
    It doesn’t seem to work in 2.0 installs-
    and I can’t tell on Tester’s site (because I’m a stupid American and only took one year of French).

    Thanks!

  10. Benoit dit:

    Hi

    First of all, thanks for this! (Not sure I fully understand how it gets called by just adding intersect paramater… but never mind, I’m not a php dev.)

    I was wondering, would you have a variant of this that would return the NUMBER of posting in the given intersection. This would greatly help us to be able to see that amongst a list of complicated intersections, only x actually would yield data..

    Many thanks

    Benoit

  11. E Becker dit:

    I’m using Wordpress 2.02 and have a lot of categories listed as children of other categories; these seem to be causing an issue with Intersect. Everytime I search on a category that has child categories, I get an SQL error WordPress database error: [Unknown table [VARIATION ON 'p2c{i}'] in where clause] (« VARIATION ON » indicating where the error changes based on the number of categories chosen).

    It seems it’s add in all the child categories of the chosen parent category to the WHERE part of the SQL statement, and choking on them (these extra tables not included in the JOIN part, so perhaps this is why?).

    Obviously, my knowledge of php and SQL is remedial at best, so I hope this explains the issue I’m having clearly.

    Thanks for the great plugin; hopefully I can get this worked out and obviously help is greatly appreciated!

    – E

  12. Evan dit:

    I’m having the same issue as E Becker above. When there are more than 2 levels of categories, it breaks the query. Here’s the error:

    WordPress database error: [Unknown table 'p2c2' in where clause]
    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_post2cat AS p2c0 ON (wp_posts.ID = p2c0.post_id) LEFT JOIN wp_post2cat AS p2c1 ON (wp_posts.ID = p2c1.post_id) WHERE 1=1 AND (p2c0.category_id = 25 AND p2c1.category_id = 47 AND p2c2.category_id = 4) AND post_date_gmt

  13. tricky dit:

    i wonder if this works on WP 2.1+

    works very fine for me on 2.0, and i’d like to upgrade but intersect is a must for me so i need to know…

  14. Ken dit:

    Do you have an example of how the plugin gets called? I am trying to call the « cat=2,19&intersect=1 within a query_posts parameter but it doesn’t work.

  15. Tester dit:

    This is exactly how it should work… I can’t upgrade past 2.1 because my host doesnt have a recent enough version of mysql.

  16. David Basulto dit:

    Will this work on 2.5?

  17. Jeff dit:

    I couldn’t get this plugin working for me on 2.5.1. But after then digging more in the codex I found this example that does work to create an intersection of 2 categories. The codex says this started with 2.3:

    query_posts(array(‘category__and’=>array(1,3)));

  18. Peter Lurie dit:

    Hi!

    This would be incredible for my needs. I am using wp 2.6 and it doesn’t seem to work.

    When I enter http://domain.com/?cat=3,6&intersect=1
    the URL expands into http://domain.com/category/category3/?intersect=1
    where it indeed shows category 3, but shows all posts, and not only those in categories 3 & 6.

    Any suggestions?
    Thanks
    Peter

Écrire un commentaire:

: (obligatoire)

Cette Page est en XHTML 1.0 Strict et CSS 2
J'utilise maintenant WordPress comme tout le monde.