[resolved] Looking for a plugin to list posts in categories (2 posts)

  1. nprior
    Posted 5 years ago #

    I'm looking for a plugin that enables me to list all the posts that have two categories in common, and ideally uses a shortcode I can embed in another page.

    I can find plugins that list all posts that have category a OR category b. I would like a plugin that lists all posts that have category a AND category b.

    I think this is possible using the category_and argument for query_posts, so if there's any way I can avoid having to roll up my sleeves and code it myself I'd really like to hear from you!

  2. nprior
    Posted 5 years ago #

    Here's a variation on Fernando Briano's List Category Posts plugin. replace his original code with this snippet - should be obvious where it goes:

    function list_category_posts($atts){
    	if($atts['name']!='default' && $atts['id']=='0'){
    		$category = 'category_name=' . $atts['name'];
    		$category_id = get_cat_ID($atts['name']);
                    $mycats = array();
                    for ($i=count($mycats)-1; $i>=0;--$i){$mycats[$i]=(int)$mycats[$i];}
    	//Build the query for get_posts()
    	$catposts = get_posts(array(
             'category__and' => $mycats,
             'orderby'       => $atts['orderby'],
             'order'         => $atts['order'],
             'numberposts'   => $atts['numberposts'],
             'excerpt'       => $atts['excerpt'],
             ) );

    Then use it like this in a post:
    [catlist id=49,14 numberposts=-1 orderby=title]

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.