: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$result = get_post( $result );
$result = $wpdb->get_var( $query );
if ( null === $result ) {
wp_cache_set( $cache_key, $result, 'post-queries' );
$result = get_post( $result );
* Retrieves the adjacent post relational link.
* Can either be next or previous post relational link.
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param bool $previous Optional. Whether to display link to previous or next post.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
* @return string|void The adjacent post relational link URL.
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
if ( $previous && is_attachment() && $post ) {
$post = get_post( $post->post_parent );
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
$post_title = the_title_attribute(
if ( empty( $post_title ) ) {
$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
$date = mysql2date( get_option( 'date_format' ), $post->post_date );
$title = str_replace( '%title', $post_title, $title );
$title = str_replace( '%date', $date, $title );
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
$link .= esc_attr( $title );
$link .= "' href='" . get_permalink( $post ) . "' />\n";
$adjacent = $previous ? 'previous' : 'next';
* Filters the adjacent post relational link.
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
* Possible hook names include:
* - `previous_post_rel_link`
* @param string $link The relational link.
return apply_filters( "{$adjacent}_post_rel_link", $link );
* Displays the relational links for the posts adjacent to the current post.
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
* Displays relational links for the posts adjacent to the current post for single post pages.
* This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins
* @since 5.6.0 No longer used in core.
* @see adjacent_posts_rel_link()
function adjacent_posts_rel_link_wp_head() {
if ( ! is_single() || is_attachment() ) {
adjacent_posts_rel_link();
* Displays the relational link for the next post adjacent to the current post.
* @see get_adjacent_post_rel_link()
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
* Displays the relational link for the previous post adjacent to the current post.
* @see get_adjacent_post_rel_link()
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
* Retrieves the boundary post.
* Boundary being either the first or last post by publish date within the constraints specified
* by `$in_same_term` or `$excluded_terms`.
* @param bool $in_same_term Optional. Whether returned post should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param bool $start Optional. Whether to retrieve first or last post.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
* @return array|null Array containing the boundary post object if successful, null otherwise.
function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
'order' => $start ? 'ASC' : 'DESC',
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
if ( ! is_array( $excluded_terms ) ) {
if ( ! empty( $excluded_terms ) ) {
$excluded_terms = explode( ',', $excluded_terms );
$excluded_terms = array();
if ( $in_same_term || ! empty( $excluded_terms ) ) {
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
if ( ! empty( $excluded_terms ) ) {
$excluded_terms = array_map( 'intval', $excluded_terms );
$excluded_terms = array_diff( $excluded_terms, $term_array );
$inverse_terms = array();
foreach ( $excluded_terms as $excluded_term ) {
$inverse_terms[] = $excluded_term * -1;
$excluded_terms = $inverse_terms;
$query_args['tax_query'] = array(
'terms' => array_merge( $term_array, $excluded_terms ),
return get_posts( $query_args );
* Retrieves the previous post link that is adjacent to the current post.
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
* @return string The link URL of the previous post in relation to the current post.
function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
* Displays the previous post link that is adjacent to the current post.
* @see get_previous_post_link()
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
* Retrieves the next post link that is adjacent to the current post.
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
* @return string The link URL of the next post in relation to the current post.
function get_next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
* Displays the next post link that is adjacent to the current post.
* @see get_next_post_link()
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
* Retrieves the adjacent post link.
* Can be either next post link or previous.
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs.
* @param bool $previous Optional. Whether to display link to previous or next post.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
* @return string The link URL of the previous or next post in relation to the current post.
function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
if ( $previous && is_attachment() ) {
$post = get_post( get_post()->post_parent );
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
$title = $post->post_title;
if ( empty( $post->post_title ) ) {
$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( 'the_title', $title, $post->ID );
$date = mysql2date( get_option( 'date_format' ), $post->post_date );
$rel = $previous ? 'prev' : 'next';
$string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
$inlink = str_replace( '%title', $title, $link );
$inlink = str_replace( '%date', $date, $inlink );
$inlink = $string . $inlink . '</a>';
$output = str_replace( '%link', $inlink, $format );
$adjacent = $previous ? 'previous' : 'next';
* Filters the adjacent post link.
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
* Possible hook names include:
* @since 4.2.0 Added the `$adjacent` parameter.
* @param string $output The adjacent post link.
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param WP_Post|string $post The adjacent post. Empty string if no corresponding post exists.
* @param string $adjacent Whether the post is previous or next.
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );
* Displays the adjacent post link.
* Can be either next post link or previous.
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param bool $in_same_term Optional. Whether link should be in the same taxonomy term.
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs.
* @param bool $previous Optional. Whether to display link to previous or next post.
* @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'.
function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
* Retrieves the link for a page number.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param int $pagenum Optional. Page number. Default 1.
* @param bool $escape Optional. Whether to escape the URL for display, with esc_url().
* If set to false, prepares the URL with sanitize_url(). Default true.
* @return string The link URL for the given page number.
function get_pagenum_link( $pagenum = 1, $escape = true ) {
$pagenum = (int) $pagenum;
$request = remove_query_arg( 'paged' );
$home_root = parse_url( home_url() );
$home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : '';
$home_root = preg_quote( $home_root, '|' );
$request = preg_replace( '|^' . $home_root . '|i', '', $request );
$request = preg_replace( '|^/+|', '', $request );
if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {
$base = trailingslashit( get_bloginfo( 'url' ) );
$result = add_query_arg( 'paged', $pagenum, $base . $request );
$result = $base . $request;
preg_match( $qs_regex, $request, $qs_match );
$parts[] = untrailingslashit( get_bloginfo( 'url' ) );
if ( ! empty( $qs_match[0] ) ) {
$query_string = $qs_match[0];
$request = preg_replace( $qs_regex, '', $request );
$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );
$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request );
$request = ltrim( $request, '/' );
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) {
$parts[] = $wp_rewrite->index;
$parts[] = untrailingslashit( $request );
$parts[] = $wp_rewrite->pagination_base;
$result = user_trailingslashit( implode( '/', array_filter( $parts ) ), 'paged' );
if ( ! empty( $query_string ) ) {
$result .= $query_string;
* Filters the page number link for the current request.
* @since 5.2.0 Added the `$pagenum` argument.
* @param string $result The page number link.
* @param int $pagenum The page number.
$result = apply_filters( 'get_pagenum_link', $result, $pagenum );
return esc_url( $result );
return sanitize_url( $result );
* Retrieves the next posts page link.
* Backported from 2.1.3 to 2.0.10.
* @param int $max_page Optional. Max pages. Default 0.
* @return string|void The link URL for next posts page.
function get_next_posts_page_link( $max_page = 0 ) {