posts_per_page => 0 список всех сообщений для определенной категории в WordPress - PullRequest
0 голосов
/ 26 марта 2019

Я работаю над веб-страницей WordPress, на которой я хочу показать нулевое сообщение для определенной категории Ниже приведен код для этого:

<code><?PHP
   $temp_args = [
       'post_type' => array('current-channel', 'post', 'current-episodes'),
       'post_status' => 'publish',
       'orderby' => array(
           'feat_yes' => 'ASC',
           'post_type' => 'ASC',
           'date' => 'DESC'),
       'posts_per_page' => $data->{"no_articles_".ICL_LANGUAGE_CODE},     // Line A
       'tax_query' => [
           [
               'taxonomy' => 'category',
               'field' => 'term_id',
               'terms' => $cat_today,
           ],
       ],

   ];
   echo '<pre>'; print_r($temp_args); echo '
'; $ q = новый WP_Query ($ temp_args); echo "Есть сообщения:"; echo '
'; print_r($q->have_posts()); echo '
'; if ($ q-> have_posts ()) { while ($ q-> have_posts ()) { $ Q-> the_post (); $ post_type = strtolower (get_post_type ()); switch ($ post_type) { case 'current-эпизоды': get_template_part ('template-parts / content-search', 'video'); перерыв; case 'current-channel': if (get_post_meta ($ post-> ID, "current_portal_end_date_timestamp", true)> time ()) { эхо "Hello World"; get_template_part ('template-parts / content-search', 'channel'); } перерыв; дело "пост": get_template_part ('template-parts / content', 'search'); перерыв; } } wp_reset_postdata (); } ?>

Я добавил Строка # A , чтобы контролировать количество сообщений для определенной категории. При значении 'posts_per_page' => 0 тогда показывается весь список постов для этой конкретной категории, что я не уверен почему.

Постановка задачи:

Мне интересно, какие изменения я должен внести в код php выше, когда 'posts_per_page' => 0, тогда он должен показывать ноль сообщений.

1 Ответ

1 голос
/ 26 марта 2019
<code><?PHP
   if( $data->{"no_articles_".ICL_LANGUAGE_CODE} >= 1 ) {
     $temp_args = [
         'post_type' => array('current-channel', 'post', 'current-episodes'),
         'post_status' => 'publish',
         'orderby' => array(
             'feat_yes' => 'ASC',
             'post_type' => 'ASC',
             'date' => 'DESC'),
         'posts_per_page' => $data->{"no_articles_".ICL_LANGUAGE_CODE},     // Line A
         'tax_query' => [
             [
                 'taxonomy' => 'category',
                 'field' => 'term_id',
                 'terms' => $cat_today,
             ],
         ],

     ];
     echo '<pre>'; print_r($temp_args); echo '
'; $ q = новый WP_Query ($ temp_args); echo "Есть сообщения:"; echo '
'; print_r($q->have_posts()); echo '
'; if ($ q-> have_posts ()) { while ($ q-> have_posts ()) { $ Q-> the_post (); $ post_type = strtolower (get_post_type ()); switch ($ post_type) { case 'current-эпизоды': get_template_part ('template-parts / content-search', 'video'); перерыв; case 'current-channel': if (get_post_meta ($ post-> ID, "current_portal_end_date_timestamp", true)> time ()) { эхо "Hello World"; get_template_part ('template-parts / content-search', 'channel'); } перерыв; дело "пост": get_template_part ('template-parts / content', 'search'); перерыв; } } wp_reset_postdata (); } } ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...