WordPress.org

Ready to get started?Download WordPress

Forums

WP Most Popular
Multiple post types? (5 posts)

  1. Simon Blackbourn
    Member
    Posted 2 years ago #

    Hi

    Great plugin thanks and really well-written too.

    I have a feature request: would it be possible to be able pass in an array of post types to the wmp_get_popular function? That way I could then show the most popular items from my whole website, at the moment I'm limited to one post type at a time.

    Thanks!
    Simon

    http://wordpress.org/extend/plugins/wp-most-popular/

  2. Mindshare Studios, Inc.
    Member
    Posted 2 years ago #

    I'd like this too.

  3. Mindshare Studios, Inc.
    Member
    Posted 2 years ago #

    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>
  4. Mindshare Studios, Inc.
    Member
    Posted 2 years ago #

    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>
  5. MattGeri
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks guys!

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

    Matt

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic