• Resolved Beee

    (@beee)


    I’m now listing the last added categories as such

    $args = array(
    	'exclude' => array(1,3,4),
    	'show_count' => 1,
    	'orderby' => 'ID',
    	'order' => 'DESC',
    	'number' => '10',
    	'title_li' => ''
    ); ?>
    wp_list_categories( $args );

    I want to query the category only if it has 3 posts or more…

    if anyone knows how to query that, plz post it

Viewing 5 replies - 1 through 5 (of 5 total)
  • I think the only way to achieve this is to use get_categories() and then loop trough the list manually and kick out every category that has less than 3 posts.

    As far as I know, there is no WordPress function that provides an argument that lets you select a minimum number of posts.

    Thread Starter Beee

    (@beee)

    I was affraid already there was nothing that could be achieved with ‘regular’ code….

    I thought the prob with get_categories() is there’s no post count (afaik)
    I do would like to show that… but then I found a term on the forlast line “$category->count” so will try to play with that…

    Yeah, count should do the trick. Filter out each category that has a value less then 3 in $category->count. ??

    Thread Starter Beee

    (@beee)

    for those who want to know how it works…

    $args = array(
    	'exclude' => array(1,3,4),
    	'show_count' => 1,
    	'orderby' => 'ID',
    	'order' => 'DESC',
    	'title_li' => ''
    );
    $categories = get_categories( $args );
    $counter = 0;
    foreach($categories as $category)
    {
    	if ( $category->count > 2 )
    	{
    		$counter++;
    		if ( $counter < 11 )
    		{
    			echo '<li class="counter-' . $counter . '"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all galleries for %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ('. $category->count . ')</li>';
    		} continue;
    	}
    }

    Thank you, it was very usefull for me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘query categories when it has at least 3 posts’ is closed to new replies.