WordPress.org

Ready to get started?Download WordPress

Forums

Adding posts from mulitple categories to one page (2 posts)

  1. Donorbrain
    Member
    Posted 1 year ago #

    HEy all,

    I've been busy with this one for a couple of hours now but it seems i've reached the limit of my PHP skills ;)

    What i want doesn't seem to be that hard or complicated.
    Basicly, i've made a template for a specific page. Within this template i'm trying to make a function like this:

    query_posts("post_type=portfolio&get_term=term_id&posts_per_page=4&orderby=rand");

    Just before the loop.
    Within this loop then, i want four posts appearing from random categories (i've got 6 now in total) and all of these posts can be random too.

    The thing is, when i run this piece of code i also get posts from the same category. I don't want that. For each of those 4 posts i want them all to be from a different category. Perhaps i should use something like this ?
    http://wpengineer.com/1719/filter-duplicate-posts-in-the-loop/

    Thanks a lot for any help or feedback!
    - JAcco
    PS
    Maybe usefull to know. These are posts from a portfolio template, hence the: " post_type=portfolio&get_term=term_id " in my code snippet.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    I think the code shown in the article 'Show X Posts For Y Categories' will do what you want.

    You will need to shuffle the $terms array and use the 'order' => 'RAND' parameter in the $args array in the posts query.

Topic Closed

This topic has been closed to new replies.

About this Topic