• Hello,

    I’ve been trying to get posts using the get_posts(‘tag=XXXX&category=NNNN’) but, it seems that I can’t use them together. I know that I have posts with the tag XXXX and I know that they are inside NNNN.

    XXXX is a normal string, and category is a Number.

    I’ve tried XXXX in uppercase (like the input) and lowercase (like the slug).

    If I make a get_posts just with the tags and then iterate using get_the_category() then I confirm that the category NNNN is assigned to the post containing that TAG.

    Could someone give me some lights?

    Thanks in advanced,
    P

Viewing 4 replies - 1 through 4 (of 4 total)
  • I had the same pb, seems that it doesn’t work. Hope it will in the 2.7 version.
    Till, you can do it this way :

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

    Has this issue been resolved yet? I am on 2.7 and still having this problem. And JFTrichard, that above code does not work, that is a “CAT OR TAG” statement, whereas, what is needed is a “CAT AND TAG” statement.

    Oops. Feel stupid, you used array_intersect, how that passed by me is unknown. I humble myself.

    From the query_posts(), article on Combining Parameters, this should work:
    query_posts('cat=NNNN&tag=XXXX+XXXX');

    Also pointing to this plugin:
    https://www.ads-software.com/extend/plugins/tdo-tag-fixes/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_posts(‘tag=XXXX&category=NNNN’) Doesn’t retrieve anything’ is closed to new replies.