Skip to content

Instantly share code, notes, and snippets.

@hykw
Last active May 24, 2016 09:07
Show Gist options
  • Save hykw/a78d1a28155d47768986 to your computer and use it in GitHub Desktop.
Save hykw/a78d1a28155d47768986 to your computer and use it in GitHub Desktop.
wordpress: WP_Query() 呼び出し例
$args = array(
'post_type' => array(
'post',
),
'post_status' => array(
'publish',
),
'posts_per_page' => 5,
'order' => 'DESC',
'orderby' => 'date',
);
$args['category_name'] = $news_cat;
$the_query = new WP_Query($args);
while ($the_query->have_posts()) {
$the_query->the_post();
get_template_part('loop', 'front');
}
wp_reset_postdata();
# https://codex.wordpress.org/Class_Reference/WP_Query
# https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Query
# http://notebook.yamamotohiroyuki.com/wordpress/2012/08/15/%E3%81%A1%E3%82%87%E3%81%84%E3%81%A1%E3%82%87%E3%81%84%E5%BF%98%E3%82%8C%E3%82%8B%E3%80%8Ewp_query%E3%80%8F%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment