Problem with Wp Query

Asked

Viewed 49 times

0

I have a loop problem when I do a wp_query. See my code:

$query_video = new WP_Query( $args );
$args = array(
    'post_type' => 'post',
    'category_name' => 'videos',
    'posts_per_page' => '4',
    'orderby' => 'rand'
);

<?php if( $query_video->have_posts()) : while( $query_video->have_posts()) : $query_video->the_post(); ?>

What I’m trying to do:

  • Bring only 4 random posts from the Videos category.
  • This category Videos is of the type Post-format Video ( I believe that this does not influence much, because I want to bring everything from the category videos.

Only he’s not showing my loop! Could you give me a Help?

1 answer

1


You have to load the $args variable before creating a new Wp_query. Just change the order and put $args and then $query_videos.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.