• I want to use code that in a twentysixteen theme widget area that already works in a twentytwelve theme widget area to display a random post but I can’t get it to work. Any ideas will be appreciated.

    `<?php $args = array(
    ‘post_type’ => ‘post’,
    ‘orderby’ => ‘rand’,
    ‘posts_per_page’=> 1);

    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query($args);
    ?>

    <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
    ” title=”<?php the_title(); ?>”><?php the_post_thumbnail(); ?><?php the_title(); ?>
    <?php wp_reset_postdata(); ?>

    <?php endwhile; ?>
    <?php endif; ?>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘WP_Query in sidebar widget area’ is closed to new replies.