• Resolved Jim

    (@releasejim)


    Hello. How can this plugin show the top 10 posts from specific categories only?
    What code can I implement to do this?

    -Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ajay

    (@ajay)

    Thread Starter Jim

    (@releasejim)

    I am a bit confused with all that code. Can you please help me further?

    I like this plugin but If I don’t find a way how to display top posts from certain categories I will have to go for another…

    If what I want is possible… could you please take the time and tell me what code to use specifically to achieve this?

    -Thanks

    Thanks alot @ajay that helpes a lot

    and for you @releasejim

    if ( function_exists( 'get_tptn_pop_posts' ) ) {
    
    	$settings = array(
    		'daily' => TRUE,
    		'daily_range' => 30,
    		'limit' => 20,
    		'strict_limit' => FALSE
    
    	);
    
    	$topposts = get_tptn_pop_posts( $settings ); // Array of posts
    	
    	$topposts = wp_list_pluck( (array) $topposts, 'postnumber' );
    	
    	$args = array(
    		'post__in' => $topposts,
    		'orderby' => 'post__in',
    		'posts_per_page' => 7,
    		'ignore_sticky_posts' => 1,
                    'category_name' => 'you-category-name' // you can find you category name in posts/category and 'slug'
    	);
    	
    	$my_query = new WP_Query( $args );
    	if ( $my_query->have_posts() ) {
    		while ( $my_query->have_posts() ) {
    			$my_query->the_post();
    			echo '<a href="' . get_permalink( get_the_ID() ) . '">';
    			the_title();
    			echo '</a>';
    			wp_reset_postdata();
    		}
    	} else {
    	}
    	wp_reset_query();
    	
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to preview posts from specific categories only?’ is closed to new replies.