Wordpress- Get posts matching particular categoty+tag

Discussion in 'WordPress' started by susan8051, May 22, 2009.

  1. #1
    get_posts() can take the argument tag ='tagname' or category='categoryname'
    but we cant club them together like get_posts(tag ='tagname'&category='categoryname')

    Any ideas to get out of this situation..

    I need to get all posts that have a particular tag and it belongs to a particular category..
     
    susan8051, May 22, 2009 IP
  2. Hakicoma

    Hakicoma Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I did a little research on your problem and it seems that there is a workaround... seems to be a well known problem of Wordpress. I can't post links for the moment, so I'll paste you the solution found on the web:

    <?php
    global $post;
    $postsByTag = get_posts('tag=Actualité');
    $postsByCat = get_posts('categorie=6');
    $postsListe = array_intersect ($postsByTag, $postsByCat);
    foreach($postsListe as $post) : ?>
    .....
    <?php endforeach; ?>

    Hope this is of any help! =)
     
    Hakicoma, May 22, 2009 IP
  3. susan8051

    susan8051 Peon

    Messages:
    1,358
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i too had came across the same.. and it gave the error

    Catchable fatal error: Object of class stdClass could not be converted to string in
     
    susan8051, May 22, 2009 IP
  4. djuicePK

    djuicePK Peon

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
  5. susan8051

    susan8051 Peon

    Messages:
    1,358
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #5
    susan8051, May 23, 2009 IP