WordPress.org

Ready to get started?Download WordPress

Forums

Showing lates post without 301 redirect (1 post)

  1. amindiary
    Member
    Posted 2 years ago #

    Hi, My WordPress website is now redirected to lates post by adding below function to function.php

    add_action( 'template_redirect', 'redirect' );
    function redirect() {
    	$args = array(
        'numberposts' => 1,
        'post_type' => 'seller',
        'post_status' => 'publish');
    	$last = wp_get_recent_posts($args);
    $last_id = $last['0']['ID'];
            if ( is_home() && ! is_paged() && ! is_archive() && ! is_tag() && !isset($_GET['ptype'])  ) :
                 wp_redirect( get_permalink($last_id) , 301 ); 
    
                    exit;
            endif;
    }

    now, I want this feature but without changing URL to latest post! I mean when you go to http://www.example.com latest post shows without a 301 redirect to http://www.example.com/article/some-other-texts

Topic Closed

This topic has been closed to new replies.

About this Topic