Warning: This function has been deprecated. Use previous_post_link() instead.

previous_post() WordPress Function

The previous_post() function is used to get the previous post in the WordPress loop. This function is used when you want to display a list of posts in reverse chronological order. The previous_post() function will return the previous post object from the WordPress loop.

previous_post( string $format = '%', string $previous = 'previous post: ', string $title = 'yes', string $in_same_cat = 'no', int $limitprev = 1, string $excluded_categories = '' ) #

Prints a link to the previous post.


Description

Top ↑

See also


Top ↑

Parameters

$format

(string)(Optional)

Default value: '%'

$previous

(string)(Optional)

Default value: 'previous post: '

$title

(string)(Optional)

Default value: 'yes'

$in_same_cat

(string)(Optional)

Default value: 'no'

$limitprev

(int)(Optional)

Default value: 1

$excluded_categories

(string)(Optional)

Default value: ''


Top ↑

Source

File: wp-includes/deprecated.php

function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {

	_deprecated_function( __FUNCTION__, '2.0.0', 'previous_post_link()' );

	if ( empty($in_same_cat) || 'no' == $in_same_cat )
		$in_same_cat = false;
	else
		$in_same_cat = true;

	$post = get_previous_post($in_same_cat, $excluded_categories);

	if ( !$post )
		return;

	$string = '<a href="'.get_permalink($post->ID).'">'.$previous;
	if ( 'yes' == $title )
		$string .= apply_filters('the_title', $post->post_title, $post->ID);
	$string .= '</a>';
	$format = str_replace('%', $string, $format);
	echo $format;
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Use previous_post_link()
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More