• Resolved ZLC

    (@kindnessville)


    Hi Martin,

    Thank you so much for your incredible plugin! I would like to universally remove the latest post from all widgets while keeping the option to randomly display the posts.

    I notice that the following solutions only work when the random option is disabled:

    function rpwwt_add_offset ( $query_args ) {
    	$query_args[ 'offset' ] = 1;
    	return $query_args;
    }
    add_filter( 'rpwwt_widget_posts_args', 'rpwwt_add_offset' );

    And…

    .recent-posts-widget-with-thumbnails ul li:first-child {display: none;}

    Is there a solution to prevent the latest post from displaying while using the random option?

    Thank you so much for your time!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Martin Stehle

    (@hinjiriyo)

    Write a plugin which extends the query parameters to exclude the ID of the latest post. “Recent Posts Widget with Thumbnails” provides the filter hook ‘rpwwt_widget_posts_args’ for that.

    Here is an untested, quick-and-dirty draft of the plugin for refinements:

    function rpwwt_omit_latest_post ( $args ) {
    	// get the latest post
    	$posts = get_posts( array( 'numberposts' => 1 ) );
    	
    	// fetch the ID of the latest post
    	$latest_post_id = $posts[0]->ID;
    	
    	// if the parameter of excluded posts IDs already exists
    	if ( array_key_exists( 'post__not_in', $args ) ) {
    		// append ID of the latest post
    		$args[ 'post__not_in' ] = $args[ 'post__not_in' ] . ',' . $latest_post_id;
    	} else {
    		// add the parameter with the ID of the latest post
    		$args[ 'post__not_in' ] = $latest_post_id;
    	}
    	
    	// return altered query parameters
    	return $args;
    	
    }
    add_filter( 'rpwwt_widget_posts_args', 'rpwwt_omit_latest_post' )
    Thread Starter ZLC

    (@kindnessville)

    I appreciate your help, Martin, but writing a plugin is very much out of my league.

    I’ll stick to displaying the posts in the standard order.

    Thanks for your time.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Remove latest post with random option’ is closed to new replies.