Skip to main content
added 32 characters in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Combine the two codes above like this:

function one_random_post_on_home_page( $query ) { if ( ! ( $query->is_home() && $query->is_main_query() ) ) return; query_posts(array('orderby' => 'rand', 'showposts' => 1)); }

add_action( 'pre_get_posts', 'one_random_post_on_home_page' );

function one_random_post_on_home_page( $query )
{
    if ( ! ( $query->is_home() && $query->is_main_query() ) )
        return;
        query_posts(array('orderby' => 'rand', 'showposts' => 1));
}

add_action( 'pre_get_posts', 'one_random_post_on_home_page' );

Combine the two codes above like this:

function one_random_post_on_home_page( $query ) { if ( ! ( $query->is_home() && $query->is_main_query() ) ) return; query_posts(array('orderby' => 'rand', 'showposts' => 1)); }

add_action( 'pre_get_posts', 'one_random_post_on_home_page' );

Combine the two codes above like this:

function one_random_post_on_home_page( $query )
{
    if ( ! ( $query->is_home() && $query->is_main_query() ) )
        return;
        query_posts(array('orderby' => 'rand', 'showposts' => 1));
}

add_action( 'pre_get_posts', 'one_random_post_on_home_page' );
Source Link

Combine the two codes above like this:

function one_random_post_on_home_page( $query ) { if ( ! ( $query->is_home() && $query->is_main_query() ) ) return; query_posts(array('orderby' => 'rand', 'showposts' => 1)); }

add_action( 'pre_get_posts', 'one_random_post_on_home_page' );