Support » Plugin: WP Most Popular » [Plugin: WP Most Popular] Multiple post types?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’d like this too.

    This code <strike>should</strike> doesn’t work for multiple post types – use the code below instead:

    <ul>
    <?php
    $my_post_type_1 = wmp_get_popular(array('limit' => 10, 'post_type' => 'my_post_type_1 ', 'range' => 'all_time'));
    $my_post_type_2 = wmp_get_popular(array('limit' => 10, 'post_type' => 'my_post_type_2', 'range' => 'all_time'));
    
    $all_types = array_merge($my_post_type_1 , $my_post_type_2);
    if(count($all_types) > 0) : foreach($all_types as $post) : setup_postdata($post); ?>
        <li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; endif; ?>
    </ul>

    Actually, I just tested my code and it didn’t work. I had to add in some type casting… here’s the updated code I’m using on my site and it works:

    <ul>
    <?php
    $documents = wmp_get_popular(array('limit' => 10, 'post_type' => 'document', 'range' => 'all_time'));
    $opinions = wmp_get_popular(array('limit' => 10, 'post_type' => 'opinion', 'range' => 'all_time'));
    $articles = wmp_get_popular(array('limit' => 10, 'post_type' => 'article', 'range' => 'all_time'));
    $videos = wmp_get_popular(array('limit' => 10, 'post_type' => 'video', 'range' => 'all_time'));
    $audios = wmp_get_popular(array('limit' => 10, 'post_type' => 'audio', 'range' => 'all_time'));
    
    $documents = (object) array_merge((array) $documents, (array) $opinions, (array) $articles, (array) $videos, (array) $audios);
    global $post;
    if(count($documents) > 0) : foreach($documents as $post) : setup_postdata($post); ?>
        <li class="<?=get_post_type($post->ID)?>">
    		<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endforeach; endif; ?>
    </ul>
    Plugin Author MattGeri

    (@mattgeri)

    Thanks guys!

    I will include this in the next version coming out this weekend.

    Matt

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WP Most Popular] Multiple post types?’ is closed to new replies.