WordPress.org

Ready to get started?Download WordPress

Forums

I Recommend This
[resolved] Use recommended posts within wp_query? (4 posts)

  1. KS Web Designer
    Member
    Posted 8 months ago #

    Thanks for this great, plugin it works brilliantly. I was just wondering, is it possible to access the number of recommendations a post has via a wp_query? Say if I wanted to order the treturned posts by number of recommendations or exclude any with less than 'x' recommendations?

    Thanks

    http://wordpress.org/plugins/i-recommend-this/

  2. Harish Chouhan
    Member
    Plugin Author

    Posted 8 months ago #

    @KS,

    Yes it is. However would require some testing.

    Have you checked this http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters?

    In wp_query you can sort using a custom meta key. i am afraid I would not be able to provide you with a complete code, but you can refer to http://wordpress.org/support/topic/meta-value-_recommended?replies=9 for some idea.

  3. andy999
    Member
    Posted 7 months ago #

    <?php 
    
    				// Create a new filtering function that will add our where clause to the query
    				function filter_where( $where = '' ) {
    				    // posts in the last 30 days
    				    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-380 days')) . "'";
    				    return $where;
    				}
    
    				add_filter( 'posts_where', 'filter_where' );
    
    				$featuredPosts = new WP_Query( array(
    				'posts_per_page' => 33,
    			    'meta_key'=>'_recommended',
    			    'orderby' => 'meta_value_num',
    			    'order' => DESC
    				) ); 
    
    				remove_filter( 'posts_where', 'filter_where' ); ?>
    
    				<?php if ( $featuredPosts->have_posts() ) : ?>
    
    				<?php while ( $featuredPosts->have_posts() ) : $featuredPosts->the_post(); ?>
    
    				<article <?php post_class('item-post block'); ?> id="post-<?php the_ID(); ?>">
    
    					<?php the_title(); ?>
    			</article> <!-- end div post -->
    
    				<?php endwhile; wp_reset_query(); ?>
    
    				<?php endif; ?>

    Enjoy!

  4. Harish Chouhan
    Member
    Plugin Author

    Posted 7 months ago #

    Thank you for sharing the code @Andy999

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.