WP_Query
is_home()
is_single()
is_page()
query_posts()
if ( have_posts() )
 while ( have_posts() )
  the_post();
query_posts( 'cat=-5' );
$posts = get_posts( 'cat=-5' );
$posts = new WP_Query( 'cat=-5' );
10 posts
10 posts
           +   10 posts
                cat = -5
max_num_pages = 3




                      index.php
404.php              max_num_pages = 5
pre_get_posts
add_action( 'pre_get_posts', 'my_func' );
function my_func( $query ) {
  $query->set( 'cat', '-5' );
}
$query->is_main_query()
add_action( 'pre_get_posts', 'my_func' );
function my_func( $query ) {
  if ( $query->is_main_query() )
    $query->set( 'cat', '-5' );
}
add_action( 'pre_get_posts', 'my_func' );
function my_func( $query ) {
  if ( $query->is_main_query() )
    if ( $query->is_search() )
      $query->set( 'post_type', 'post' );
}
add_action( 'pre_get_posts', 'my_func' );
function my_func( $query ) {
  if ( $query->is_main_query() )
    if ( $query->is_search() )
      $query->set( 'posts_per_page', 30 );
}
add_action( 'pre_get_posts', 'my_func' );
function my_func( $query ) {
  if ( $query->is_main_query() )
    if ( $query->is_home() )
      $query->set( 'post_type', array(
        'post',
        'book',
      ) );
}
query_posts();
$posts = get_posts();
$posts = new WP_Query();
$popular = new WP_Query( 'cat=3' );
while ( $popular->have_posts() ) {
  $popular->the_post();
  ...
}
$popular = new WP_Query( 'cat=3' );
while ( $popular->have_posts() ) {
  $popular->the_post();
  ...
}

// Основной запрос
while ( have_posts() ) {
  the_post();
  ...
}
// Основной запрос
while ( have_posts() ) {
  the_post();
  ...

    $category = get_the_category();
    $related = new WP_Query( 'cat=' ... );
    while ( $related->have_posts() ) {
      $related->the_post();
      ...
    }
}
query_posts()
$wp_query
function have_posts() {
  global $wp_query;
  return $wp_query->have_posts();
}
$wp_query =& $wp_the_query;
function &query_posts( $query ) {
  ...
  unset( $wp_query );
  $wp_query = new WP_Query();
  return $wp_query->query( $query );
}
function wp_reset_query() {
  ...
  unset( $wp_query );
  $wp_query =& $wp_the_query;
}
$popular = new WP_Query( 'cat=3' );
while ( $popular->have_posts() ) {
  $popular->the_post();
  ...
}

// Основной запрос
while ( have_posts() ) {
  the_post();
  ...
}
query_posts( 'cat=3' );
while ( have_posts() ) {
  the_post();
  ...
}
wp_reset_query();

// Основной запрос
while ( have_posts() ) {
  the_post();
  ...
}
Если нужно изменить основной запрос




       pre_get_posts
Если нужен вторичный запрос




new WP_Query; get_posts()
Если нужна головная боль




 query_posts()
Секреты WP_Query
Секреты WP_Query

More Related Content

PDF
Knowlage
PDF
PDF
PHPのすべらない話#3
PDF
Адаптация TInyMCE редактора под нужды клиента by Vitaly Nikolaev
PDF
Add tag shortcode
DOCX
Simular un next del recordset en php de forma rudimentaria
PPTX
8. CodeIgniter move2
PDF
Dušan Kasan - Zrefaktoruj cykly na kolekce
Knowlage
PHPのすべらない話#3
Адаптация TInyMCE редактора под нужды клиента by Vitaly Nikolaev
Add tag shortcode
Simular un next del recordset en php de forma rudimentaria
8. CodeIgniter move2
Dušan Kasan - Zrefaktoruj cykly na kolekce

What's hot (20)

KEY
jQuery プラグインの作り方
PDF
Jquery2
PDF
Analizador sintáctico de Pascal escrito en Bison
PDF
Making DSL with []
PDF
Templating WordPress
PDF
BABELで、ES2015(ES6)を学ぼう!
TXT
With enter
PDF
12 PREMIO “1ER LUGAR” 9NA COPA GRUNDY.PDF
PDF
PHP Profiling
TXT
Miniray.php
PDF
jQuery PLUGIN
PDF
Quiz Component For Joomla
PDF
Sumahexavector
ODP
Jquery Plugin
PDF
PDF
Feeds. использование и создание плагинов. Feeds API
TXT
Minishell
PDF
Working With Ajax Frameworks
PDF
Web Programming - Toko Bunga Red Flower
PPS
jQuery プラグインの作り方
Jquery2
Analizador sintáctico de Pascal escrito en Bison
Making DSL with []
Templating WordPress
BABELで、ES2015(ES6)を学ぼう!
With enter
12 PREMIO “1ER LUGAR” 9NA COPA GRUNDY.PDF
PHP Profiling
Miniray.php
jQuery PLUGIN
Quiz Component For Joomla
Sumahexavector
Jquery Plugin
Feeds. использование и создание плагинов. Feeds API
Minishell
Working With Ajax Frameworks
Web Programming - Toko Bunga Red Flower
Ad

Viewers also liked (9)

PDF
The Settings API
PDF
Пожиратели памяти в WordPress
PDF
WordPress под нагрузкой: масштабирование и отказоустойчивость
PDF
Memory Management in WordPress
PDF
7 убийц производительности WordPress
PDF
Почему HTTPS соединение необходимо реализовать на Вашем сайте?
PDF
Основые безопасности WordPress
PDF
Цикл разработки WordPress
The Settings API
Пожиратели памяти в WordPress
WordPress под нагрузкой: масштабирование и отказоустойчивость
Memory Management in WordPress
7 убийц производительности WordPress
Почему HTTPS соединение необходимо реализовать на Вашем сайте?
Основые безопасности WordPress
Цикл разработки WordPress
Ad

More from Konstantin Kovshenin (7)

PDF
Scaling out with WordPress
PDF
Будущее WordPress (SPB, 2014)
PDF
Road to Platform @ WordPress.com VIP Workshop 2014
PDF
Будущее WordPress
PDF
Как повысить скорость вашего сайта на WordPress
PDF
Things I Wish I Had Known Before Developing a WordPress Theme
PDF
7 Tips for Better WordPress Theme Development
Scaling out with WordPress
Будущее WordPress (SPB, 2014)
Road to Platform @ WordPress.com VIP Workshop 2014
Будущее WordPress
Как повысить скорость вашего сайта на WordPress
Things I Wish I Had Known Before Developing a WordPress Theme
7 Tips for Better WordPress Theme Development

Секреты WP_Query