WordPress.org

Support

Support » How-To and Troubleshooting » Related posts using parent and sub categories

Related posts using parent and sub categories

  • waveminded

    @waveminded

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • waveminded

    @waveminded

    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.

    waveminded

    @waveminded

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Related posts using parent and sub categories’ is closed to new replies.
Skip to toolbar