Support » Plugin: Recent Posts Widget With Thumbnails » One post per author

  • Hello,

    I modified a function of the rpwwt plugin to show the post author’s avatar.

    
    	private function the_first_post_image () {
    		echo get_avatar( get_the_author_meta('user_email'), $size = '64');
    		return true;
    	}
    

    It will not be orthodox but function because I don’t use “first post image” features.

    Now I would like, however, to show only the last post of the author so that even if he has written 10 in a row, I occupy only one place, leaving evidence also to the other authors.

    I found this piece of code online but I wouldn’t know how to implement it.

    
    global $wpdb;
    function one_post_per_author_post_where($where) {
    	global $wpdb;
    	if(!is_author() && !is_admin()) {
    		return $where .= " AND wp_posts.id = (select id from {$wpdb->prefix}posts p2 where p2.post_status = 'publish' and p2.post_author = {$wpdb->prefix}posts.post_author order by p2.post_date desc limit 0,1)";
    	}
    }
    add_filter("posts_where_request", "one_post_per_author_post_where");
    

    probably, I add, we will have to put somewhere …

    
    remove_filter('posts_where_request','one_post_per_author_post_where'); 
    

    Someone could help me?

    Bye!
    thank you
    math

    • This topic was modified 3 weeks, 3 days ago by math4music.
Viewing 2 replies - 1 through 2 (of 2 total)
  • I solved.
    I applyed the filter just before

    
    		// run the query: get the latest posts
    		$r = new WP_Query( apply_filters( 'rpwwt_widget_posts_args', $query_args ) );
    

    an removed just after.

    thank you
    math

    Plugin Author Martin Stehle

    (@hinjiriyo)

    That is not a good place since the next upgrade will overwrite any changes you made in the plugin.

    It is often advised tp insert such pieces of code into the file ‘functions.php’. You find that file in the folder of the active theme. But the next upgrade of the theme will overwrite your changes, too. And if you’d change the theme, the piece of code has to be inserted into the ‘functions.php’ of the new theme – a situation often forgotten.

    The safest way to store additional functions using hooks is in an own plugin. And it is an easy-to-do way.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.