Forums

[resolved] 1 Query for both category and tags (9 posts)

  1. jazbek
    Member
    Posted 2 years ago #

    Hi, I'm using wp 2.7 and need to come up with a query that will give me all posts in the Audio category, all posts tagged with 'podcast' and all posts tagged with 'audio', all in one query result. I've tried this:

    query_posts('cat=3422&tag=audio,podcast'); // 3422 is the audio category ID

    query_posts('category_name=audio&tag=audio,podcast');

    and both are giving me an empty page. however, if i do either:
    query_posts('cat=3422');

    or
    query_posts('tag=audio,podcast');

    I get results. How can I combine the 2?

  2. xdesi
    Member
    Posted 2 years ago #

    How about:

    query_posts('cat=3422&tag=audio+podcast'); // 3422 is the audio category ID

  3. jazbek
    Member
    Posted 2 years ago #

    wouldn't that only give me posts that are tagged with both audio and podcast? i need either tag..

    yeah, just tried it out and it gives me no results.

  4. xdesi
    Member
    Posted 2 years ago #

    Yeah sorry you are right. Does it work if you are querying the category and just one tag?

    E.G do:

    query_posts('cat=3422&tag=audio');

    and

    query_posts('cat=3422&tag=podcast');

    Both output expected results?

  5. jazbek
    Member
    Posted 2 years ago #

    If I just do one tag with the category, I still get no results.

  6. xdesi
    Member
    Posted 2 years ago #

    Does this:

    query_posts('cat=3422&tag=audio+audio');

    Or:

    query_posts('cat=3422&tag=audio&order=ASC');

  7. jazbek
    Member
    Posted 2 years ago #

    Neither give me any results. I discovered that I think it is looking for posts tagged with audio or podcast *inside* the Audio category.. which there are none.

    I think I am going to have to just move all the posts with those 2 tags into the Audio category.

  8. xdesi
    Member
    Posted 2 years ago #

    Ah I thought you wanted cat AND tag not cat OR tag..

    I don't think it's possible with a simply query, but maybe possible with a custom select query

    The other option would just to retrieve all posts and use wordpress conditionals to display only the posts you wanted (from the cat or with the tags), but I don't think this is good practice..

  9. jazbek
    Member
    Posted 2 years ago #

    Heh.. yeah retrieving all posts is not going to be a good idea, I think there's almost 2000.

    I could write a custom select, but I think putting all these posts into the Audio category is going to be the cleanest solution. Honestly there's no good reason that some are tagged and some are categorized.. the data entry was just inconsistent before the client came to me.

    Thanks for all your help, though! I really appreciate the effort. :)

Topic Closed

This topic has been closed to new replies.

About this Topic