WordPress.org

Ready to get started?Download WordPress

Forums

Related posts using parent and sub categories (3 posts)

  1. waveminded
    Member
    Posted 4 years ago #

    Ok, here's the scenario. I'm using WordPress as a directory database. I have this category structure
    - The Directory (grand parent)
    -- City (parent)
    --- Hotels (child)
    --- Attractions (child)
    --- Restaurants (child)

    I'm viewing a single post 'hotel california' which resides in the 'hotels' category and has the parent 'city'.

    I would like to display 5 random posts from the parent 'city' but only including the child categories 'restaurants' and 'attractions' and excluding the current category of 'hotels' as sort of a "what's nearby" feature, yet excluding establishments of the same category like another hotel.

    I've done quite a bit of searching and have been successful pulling posts from the parent category, but I can't figure a way to exclude the current category.

  2. waveminded
    Member
    Posted 4 years ago #

    I'm getting there but I'm stuck here... trying to use query_post specifying the parent yet excluding one of the children

    $rand_posts = query_posts(
    	array(
    		'cat' => 4,-15,
    	));
    foreach ($rand_posts as $post) : setup_postdata($post);

    Tried using category__and also, no luck. ID 4 is the parent and 15 is the child.

  3. waveminded
    Member
    Posted 4 years ago #

    I'm still struggling with this and haven't found a solution. Anyone else have any bright ideas. Much appreciated!

Topic Closed

This topic has been closed to new replies.

About this Topic