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

  1. KS Web Designer
    Posted 2 years 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?



  2. Harish Chouhan
    Plugin Author

    Posted 2 years ago #


    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
    Posted 1 year ago #

    				// 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,
    			    '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; ?>


  4. Harish Chouhan
    Plugin Author

    Posted 1 year ago #

    Thank you for sharing the code @Andy999

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • I Recommend This
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.